Search code examples
pdfyamllatexquarto

How to override default titlefont in quarto?


In my header I would like to specify a different font for the title like I did for the section and subsection headings, however when I try adding a title font I get the error

LaTeX3 Error: Command '\titlefont' already defined!

However, i'm not sure where the titlefont is already defined. I tried running it without the sansfont specification since I thought that it applied to all titles and headings, but I still got the same error.

format: 
  pdf: 
    mainfont: Calibri
    mainfontoptions: 
      - Color=154a39
    sansfont: Overpass-Light
    include-in-header: 
      text: |
            \newfontfamily\sectionfont[Color=ff7832]{Overpass-ExtraBold}
            \newfontfamily\subsectionfont[Color=ff7832]{Overpass-ExtraBold}
            \newfontfamily\titlefont[Color=154a39]{Overpass-Light}
            \addtokomafont{section}{\sectionfont}
            \addtokomafont{subsection}{\subsectionfont}
            \addtokomafont{title}{\titlefont}

Solution

  • As explained in this answer, since there's already a defined command \titlefont, you can create a new command with an arbitrary name (for example I have used the name \tfont to change the title font).

    ---
    title: "Changing Title font"
    format: pdf
    mainfont: "Libertinus Sans"
    mainfontoptions: 
      - Color=154a39
    include-in-header:
      text: |
        \usepackage{lipsum}
        \newfontfamily\tfont[Color=Green]{Roboto Mono}
        \addtokomafont{title}{\tfont}
        \newfontfamily\sfont[Color=ff7832]{Comic Sans MS}
        \addtokomafont{section}{\sfont}
        
    ---
    
    ## Quarto
    
    \lipsum[1]
    
    

    changing title font specifically