Search code examples
pdflatexquarto

Specify custom fonts and attributes for H1-H6 headings in quarto PDF


I would like to set different sizes and styles of the free overpass font for the H1 & H2 headers in my document.

Using this answer I was able to successfully specify Overpass for all headings in my document but have not been able to isolate specific headings (e.g., chapter, section, paragraph as laid out in the Koma script.

I tried implementing the syntax from this solution used to specify times roman for all heading fonts, but got an error that reads "Package scrkbase Error: font of element `chapter' can't be used.".

Looking at the quarto forum and this tex post, I tried adding the xltxtra packages and setting \newfontfamily, but still no luck.

Ultimately, I would like to use the overpass extra bold font and specify different sizes, but i'm unsure if this is because the syntax to specify the heading section in the YAML is wrong, or if I need to do something else to add a font that is not already built in.

format: 
  pdf: 
    mainfont: Calibri
    sansfont: Overpass
    include-in-header: 
      text: | 
        \usepackage{xltxtra}
        \newfontfamily\overpass{Overpass}
        \usekomafont{chapter}{\Overpass-ExtraBold}
standalone: false
toc: true
editor: visual
tbl-colwidths: auto
include-in-header: 
    text: |
      \usepackage{fancyhdr}
      \pagestyle{fancy}
      \fancyhf{}
      \rhead{\includegraphics[width = .25\textwidth]{logo.png}}
      \cfoot{\thepage}
      \usepackage{float}

Solution

  • We can create new commands like \sectionfont or \subsectionfont for loading a particular font family with \newfontfamily (read the fontsepc manual, p-13 to know the details) and then use that command \addtokomafont to apply that font-family to a specific element like (section, subsetion, etc.)

    ---
    format: pdf
    mainfont: "Calibri"
    include-in-header:
      text: |
        \newfontfamily\sectionfont[Color=ff7832]{Libertinus Sans}
        \newfontfamily\subsectionfont[Color=MediumBlue]{Comic Sans MS}
        \newfontfamily\subsubsectionfont[Color=Green]{Roboto Mono}
        \addtokomafont{section}{\sectionfont}
        \addtokomafont{subsection}{\subsectionfont}
        \addtokomafont{subsubsection}{\subsubsectionfont}
    ---
    
    # H1 heading (section)
    
    ## H2 heading (subsection)
    
    ### H3 heading (subsubsection) 
    
    Quarto enables you to weave together content and executable code into a 
    finished document. To learn more about Quarto see <https://quarto.org>.
    
    

    different fonts and style for section, subsection, subsubsection