Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing font in PDF produced by rmarkdown

I am producing reports using rmarkdown. When knitting a PDF

--- title: "Untitled" output: pdf_document --- 

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. enter image description here 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.

Question: How do I change the font in the PDF produced by rmarkdown?

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 

I've never used LaTeX and don't want to get into it at this very mom

like image 769
andrey Avatar asked Jun 26 '14 01:06

andrey


People also ask

How do I change the font in RMarkdown?

To change the font size, you don't need to know a lot of html for this. Open the html output with notepad ++. Control F search for "font-size". You should see a section with font sizes for the headers (h1, h2, h3,...).

What font does RMarkdown use?

The RMarkdown output is based on LaTeX, and the default LaTeX font is Computer Modern. You will need to download and install the font on your computer. The CMU Serif version of this font is probably the one you want.

How do I use R markdown in PDF?

To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.

How do you change the font on overleaf?

Changing default font typeface The font can also be changed for a specific element in the document. The command \fontfamily{qcr}\selectfont will set the TeX gyre cursor font typeface, whose fontcode is qcr , for the text inside the braces. A lot more LaTeX font typefaces are available, see the reference guide.


1 Answers

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 --- 

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 

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

like image 62
andrey Avatar answered Sep 30 '22 06:09

andrey