更改 rmarkdown 生成的 PDF 中的字体 [英] Changing font in PDF produced by rmarkdown

查看:37
本文介绍了更改 rmarkdown 生成的 PDF 中的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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.

会话信息()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

使用默认字体生成 PDF,而不是 Calibri,但是,字体选项传递正常.

produces the PDF with default font, not Calibri, however, the font option is passed fine.

这篇关于更改 rmarkdown 生成的 PDF 中的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆