更改rmarkdown生成的PDF中的字体 [英] Changing font in PDF produced by rmarkdown
问题描述
我正在使用rmarkdown生成报告.编织PDF时
I am producing reports using rmarkdown. When knitting a PDF
---
title: "Untitled"
output: pdf_document
---
我想指定用于创建PDF的字体.官方文档(请参阅"LaTeX选项"部分)说我可以做到这一点.
但是,我从未使用过LaTeX,也无法理解如何在rmarkdown
包所使用的.Rmd文档顶部的YAML选项中进行这种选择.
I would like to specify the font to be used in creating the PDF. The official documentation (see section "LaTeX Options) says I can do this.
However, I've never used LaTeX and fail to understand how such selection can be made in YAML options at the top of the .Rmd document used by rmarkdown
package.
sessionInfo() R版本3.1.0(2014-04-10) 平台:x86_64-w64-mingw32/x64(64位)
sessionInfo() R version 3.1.0 (2014-04-10) Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_1.0.0 RODBC_1.3-10 knitr_1.6 dplyr_0.2
我从没使用过LaTeX,也不想在这个妈妈的身边涉足
I've never used LaTeX and don't want to get into it at this very mom
推荐答案
YAML选项中的缩进是有意义的.正如说明所指出的:请注意,这些选项不会出现在输出部分的下面,而是会出现在顶层以及标题,作者等."因此,
The indentation in YAML options is meaningful. As the instructions point out "note that these options do not appear underneath the output section but rather appear at the top level along with title, author, etc.)". So,
---
output:
pdf_document:
latex_engine: xelatex
sansfont: Calibri Light
---
会产生未使用的参数错误,而
will produce an unused argument error, while
---
output:
pdf_document:
latex_engine: xelatex
sansfont: Calibri Light
---
将完成这项工作.此外,在YAML之后插入的LaTeX命令似乎会覆盖它:
will do the job. In addition, LaTeX commands inserted after YAML seem to override it: so
---
output:
pdf_document:
latex_engine: xelatex
sansfont: Calibri Light
---
\fontsize{12}{22}
\fontseries{b}
\selectfont
生成具有默认字体而不是Calibri的PDF,但是可以很好地传递font选项.
produces the PDF with default font, not Calibri, however, the font option is passed fine.
这篇关于更改rmarkdown生成的PDF中的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!