如何在R markdown文档中更改字体大小和类型?

5

例子:

---
output: pdf_document
mainfont: Times New Roman
fontsize: 12pt
spacing: 1.1
geometry: "left=1in,right=1in,top=0.5in,bottom=1in"
vspace: 4pt
---

This line is normal text.

This line uses Garamond font and font size 14.

This line uses arial font and font size 16.

This line is normal text.

我尝试了几种选项,但都没有起作用。如果有方法可以实现,请告诉我。


这实际上是一个LaTeX问题,不幸的是不是R或Rmd问题。在https://tex.stackexchange.com/搜索,你可能会找到几个选项。 - r2evans
1个回答

7

我们可以在你的rmarkdown脚本中使用LaTeX代码。使用\fontfamily{}设置字体类型,一些字体代码可以在这里找到。(请注意,我在这里使用Palatino字体,因为我的系统上可能没有安装Garamond字体。) 使用\fontsize{}{}设置字体大小,第一个{}表示大小,第二个表示间距。为了使其仅为临时修改,建议将其嵌入\begingroup\endgroup中。保留YAML头文件不变。

This line is normal text.

\begingroup
\fontfamily{ppl}\fontsize{14}{16}\selectfont
This line uses Garamond font and font size 14.
\endgroup

\begingroup
\fontfamily{phv}\fontsize{16}{18}\selectfont
This line uses arial font and font size 16.
\endgroup

This line is normal text.

结果

这里输入图片描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接