Search code examples
rlatexr-markdownpdflatexxelatex

Changing font family for a paragraph in latex rmarkdown


does anyone know how to change of font family in the middle of a rmarkdown document?

I am currently using the following code but it resets the given text to computer modern, it is like it just never finds any other font. please help

---
title: ''
output:
  pdf_document:
    latex_engine: xelatex
    keep_tex: yes
geometry: left=0.35in,right=0.35in,top=0.3in,bottom=0.3in
header-includes:
- \usepackage{graphicx}
- \usepackage{fancyhdr}
- \usepackage{fontspec}
- \pagestyle{fancy}
- \renewcommand{\headrulewidth}{0.0pt}
fontsize: 9pt
---
\begingroup
\fontfamily{pag}\fontsize{18}{16}\selectfont
\textcolor{black}{tasks}
\endgroup

In addition does anyone know which fonts I can use? I cant find a list that works.


Solution

  • You are using xelatex, so you can use whatever font you have installed on your operating system

    ---
    title: ''
    output:
      pdf_document:
        latex_engine: xelatex
        keep_tex: yes
    geometry: left=0.35in,right=0.35in,top=0.3in,bottom=0.3in
    header-includes:
    - \usepackage{graphicx}
    - \usepackage{fancyhdr}
    - \usepackage{fontspec}
    - \pagestyle{fancy}
    - \renewcommand{\headrulewidth}{0.0pt}
    fontsize: 9pt
    ---
    Global
    
    \begingroup
    \setmainfont{Arial}
    \fontsize{18}{16}\selectfont
    \textcolor{black}{tasks}
    \endgroup
    
    Global
    

    enter image description here