Change Title/Headings Font in Quarto PDF Output
Asked Answered
C

2

6

When RMarkdown .rmd documents are knitted as PDF, the text body as well as the title, subtitle and headings are rendered in the same LaTeX standard font.

When rendering a Quarto .qmd document as PDF, the font for the text body remains the same, but the title, subtitle and headings are rendered in a different font, without serifs.

To achieve consistency between the outputs of older R Markdown documents and newer Quarto documents, I would like to change the font for the title, subtitle and headings back to the normal font. How can I achieve this?

I tried using fontfamily: in the YAML header, but this did not find the fonts I wanted. I had some success by using \setkomafont{section}{\normalfont} in include-in-header:, as this did change the font, but only for h1 headings, not for h2 nor for the title or subtitle. It also removed all other formatting for h1 (e.g. fontsize, bold, etc.), which is not what I want.

Clementclementas answered 6/9, 2022 at 22:4 Comment(0)
F
9

Using this answer from Tex StackExchange we can do this in quarto easily.

---
title: "Fonts"
subtitle: "Changing fonts of title, subtitle back to normal font"
author: "None"
format:
  pdf:
    include-in-header:
      text: |
        \addtokomafont{disposition}{\rmfamily}
---

## Quarto

Quarto enables you to weave together content and executable code into a 
finished document. To learn more about Quarto see <https://quarto.org>.

## Running Code

When you click the **Render** button a document will be generated that includes
both content and the output of embedded code.

Using the default fonts for title/heading in quarto pdf document


And of course, check the section 3.6 - Text Markup of KOMA-Script manual, which provides a very detailed list of elements (like author, chapter, title, subtitle, date, etc.) for whose such changes can be done.

Flivver answered 7/9, 2022 at 3:19 Comment(1)
Thank you so much! I was struggling to find this.Just
E
8

If the font used in the body is known, then you can set the font used in title and headings with sansfont: .... It's wise to also set mainfont to make sure they are the same.

The default font used is Latin Modern Roman, so adding this to the YAML frontmatter should do it:

---
mainfont: Latin Modern Roman
sansfont: Latin Modern Roman
---
Emmons answered 7/9, 2022 at 5:28 Comment(1)
Setting the sansfont did the trick here for me.Fluorescein

© 2022 - 2024 — McMap. All rights reserved.