What is the "correct" highest heading level to use in the body of an R Markdown file?

Hi everyone,

I wondered which is the "correct" highest heading level in R Markdown documents? My impression was that level 1 headings (single #) are usually reserved for the title (given in the YAML) in R Markdown or chapter in bookdown. So in the body of the markdown after the YAML header, you would only use level two or higher headings. Unfortunately, if I follow that rationale and activate the numbered section option for HTML documents, i.e.

---
title: "Foo"
output:
  html_document:
    number_sections: true
---

all headings will start with 0. in the HTML output, and only level 1 headings will increase the first number.

My questions:

  1. Is my understanding correct that you should use level two headings or higher in the body of markdowns in general? (I can see, for example, that some slide packages allow the use of level 1 headings for starting a new slide.)

  2. If I only use level two headings or higher in the body of the markdown, how can I exclude the level 1 headings from the numbering of sections (i.e. how do I get rid of the 0. from each section)?

Thanks!

You can use level 1 in the body. The title element will be different than a level 1 header usually, it could depend on the template. That is why numbering section by Pandoc will consider level 2 heading as x.x number.

Pandoc has an option to shift level if needed : Pandoc - Pandoc User’s Guide
This will allow to consider level 2 as level 1

---
title: "Foo"
output:
  html_document:
    number_sections: true
    pandoc_args: --shift-heading-level-by=-1
---

## Test
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.