这是我的第一份Markdown报告,我试着把它直接写在PDF上。我需要使用字体,但导出失败了:
Package fontspec Error: The font "Times New Roman" cannot be found.
我已经试过这些代码了
font-family: Times New Roman
或
mainfont: Times New Roman
或
header-includes:
- \usepackage{fontspec}
- \setmainfont{Times New Roman}但这些密码都不起作用。
谢谢!
发布于 2019-05-02 05:03:04
正如@RalfStubner已经提到的,您可以使用TeX Gyre Termes嵌入像Times New Roman这样的字体。
安装tex-gyre
为了使用TeX Gyre Termes,您需要从CTAN安装tex-gyre包。如果您已经安装了@Yihui的TinyTeX,请在R控制台上键入以下代码。
tinytex::tlmgr_install("tex-gyre")上面的代码相当于在bash中执行下面的代码。
tlmgr install tex-gyre提供.tex文件以指定您想要的字体
在YAML头中设置mainfont:也应该有效。但是,这里我展示了如何通过将.tex文件(例如font-config.tex )包含到YAML部分来设置字体。通过font-config.tex文件,您可以配置更详细的选项,如Scale=MatchUppercase。
在下面的font-config.tex中,TeX Gyre Termes或Times设置为主字体(\rmfamily),而TeX Gyre Heros则指定所谓的Helvetica或Arial为serif字体(\sffamily)。将文件保存在当前目录中。
font-config.tex
\usepackage{fontspec}
%rmfamily
\setmainfont[Scale=MatchUppercase]{TeX Gyre Termes} %Times New Roman
%sffamily
\setsansfont[Scale=1]{TeX Gyre Heros} %So called Helvetica, Arial将font-config.tex包含到YAML头中
您可以从YAML头调用font-config.tex,如下所示。
---
title: "The definitive MWE"
subtitle: "Oh, yeah"
author: "CLR"
output:
bookdown::pdf_document2:
number_sections: true
latex_engine: xelatex #or lualatex
keep_tex: true
includes:
in_header:
- font-config.tex
---
*Hellow world!* in Times New Roman.
\textsf{Hellow world!} in Helvetica. https://stackoverflow.com/questions/55871158
复制相似问题