61

I am trying to create a report in R markdown that has sections ordered

  1. Section 1 Header

    1.1 sub section 1

    1.2 sub section 3

  2. Section 2 Header

    2.1

    2.2 sub section

      2.2.1 another sub section
    

Is there a way get R markdown to generate an ordered list like this?

Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
H.Bananas
  • 711
  • 1
  • 6
  • 5

1 Answers1

133

Add the option number_sections: true to your YAML header:

---
title: "My Report"
output: 
  html_document:
    number_sections: true
---

# Main Section

## 2nd Level

### 3rd Level

And voilá, your sections are numbered:

The above text in an image with numbered sections

llrs
  • 3,308
  • 35
  • 68
Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
  • Is there a way to reference the automatically numbered section from within the markdown? [This question](https://stackoverflow.com/questions/2822089/how-to-link-to-part-of-the-same-document-in-markdown/58539106#58539106) asks how to link to a custom description; I want to get the generated section (or subsection) number. – orrymr Jan 08 '20 at 07:16