11

I gave up. I can't find any working solution to change font type in my R Markdown document. I tried a lot of stuff, for example:

---
output: word_document    
sansfont: Calibri Light
---

But RStudio just ignores it. Can you help me? I need Times New Roman font in my pdf/word document.

Regards

Tomasz Wojtas
  • 756
  • 2
  • 6
  • 12
  • Note that "Document fonts (works only with xelatex and lualatex, see the latex_engine option)". So I doubt you can do this for word output. If you want pdf, then use xelatex or lulatex. If pdf is OK for you, then this may be a duplicate of http://stackoverflow.com/questions/24421235/changing-font-in-pdf-produced-by-rmarkdown – dww Apr 30 '16 at 22:32
  • So there is no option to change font in my word output? – Tomasz Wojtas May 02 '16 at 12:22
  • 1
    Yes, it is possible to change it. This may help: http://rmarkdown.rstudio.com/articles_docx.html – AJMA Oct 16 '17 at 10:42

2 Answers2

13

This worked for me. Try using mainfont instead of sansfont, and set latex_engine to either xelatex or lualatex.

---
output: 
  pdf_document:
    latex_engine: xelatex
mainfont: Times New Roman
---
7

Another option: for a pdf document, I used:

output: pdf_document
fontfamily: arev

In my YAML header.

Nova
  • 5,423
  • 2
  • 42
  • 62
  • Hi, I have a doubt. Whats the difference between set a font in my YAML and outside the YAML? – Laura Oct 04 '19 at 16:07
  • 1
    Hi Laura, sometimes you can set a font with a cascading style sheet (css) outside your YAML. – Nova Oct 04 '19 at 19:05
  • just to note that this works with pdflatext, when the answer above doesn't – pluke Jan 18 '22 at 12:38