Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number some sections with rmarkdown

Tags:

r

r-markdown

I am writing a manuscript with rmarkdown.

If I want to number all sections, I can use YAML like this

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

See Automatically number sections in RMarkdown

But I only want to number some sections, so my document looks like

Abstract
1. Introduction
2. Methods
3. Results
References

Is there anyway to do this?

like image 521
Richard Telford Avatar asked Dec 22 '17 23:12

Richard Telford


1 Answers

From the Pandoc User Guide you want to add the .unnumbered attribute to the header. This is done using:

# My header {.unnumbered}

or the shortcut

# My header {-}

For example, using the following document

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

# Abstract {-}

# Introduction

# Methods

# Results

# References {-}

The HTML produced renders as:

enter image description here

like image 186
Gavin Simpson Avatar answered Oct 03 '22 08:10

Gavin Simpson