Search code examples
rpdflatexquarto

Change fonts in quarto pdf document


How to customize fonts in a quarto pdf document? I realized of the existence of mainfont and fontfamily options, but the documentation doesn't provide examples of how to use them and which fonts are available. Also, what are the fonts available for monofont?

Here is the documentation: https://quarto.org/docs/reference/formats/pdf.html#fonts


Solution

  • As said in the documentation, you can use system fonts (i.e. fonts installed in your system). So specify the font family of your system fonts as value of mainfont and/or monofont yaml key while using xelatex or lualatex as pdf-engine.

    Now if you want to get the list of fonts installed in your system, you can use system_fonts() function from {systemfonts} package.


    ---
    title: "Fonts in Quarto"
    format: pdf
    pdf-engine: xelatex
    mainfont: Lato
    monofont: Roboto
    ---
    
    
    ## Fonts
    
    - mainfont: For LaTeX output, the main font
    family for use with xelatex or lualatex. 
    Takes the name of any system font. 
    
    - monofont: For LaTeX output, the monospace 
    font family for use with xelatex or lualatex:
    take the name of any system font.
    
    
    ## Fonts available in system
    
    ```{r}
    # install.packages("systemfonts")
    systemfonts::system_fonts()
    ```
    

    Also note that, if you use fontfamily to set the font-family, you need to use pdflatex as pdf-engine.