Changing font in PDF produced by rmarkdown Changing font in PDF produced by rmarkdown r r

Changing font in PDF produced by rmarkdown


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: xelatexsansfont: 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.


Just a quick example.add these lines to your RMD main text area and see the effects.

\fontfamily{cmr}\fontsize{12}{22}\fontseries{b}\selectfont

Hope this may help


I use pdfLatex, so almost nothing worked until I use "header-includes", like this:

---title: "TITLE"author: "ANDRES"output: pdf_documentfontsize: 11ptheader-includes:  % Allows me to use and print accented characters (document is in Spanish)  \usepackage[T1]{fontenc}  \usepackage[utf8]{inputenc}  % Set up the document in Spanish  \usepackage[spanish]{babel}  % It allows me to place the tables or images where I want, whether there is space or not  \usepackage{float}  % It has several commands to have more control over the tables (at least I use it for this)  \usepackage{array}  % For custom headers and footers  \usepackage{fancyhdr}  % This line allows me to manipulate images within latex  \usepackage{graphicx}  % This package has several uses, for this document I used it to manage hyperlinks and introduce metadata to the document  \usepackage{hyperref}  % These lines define the font that I want to use in the document  \usepackage{helvet}  \renewcommand{\familydefault}{\sfdefault}---