Home > other >  Remove chapter headings in Rmarkdown for PDF reports
Remove chapter headings in Rmarkdown for PDF reports

Time:10-04

I am aware that there are already an infinite number of entries here about the YAML header in rmarkdown. However, I have not yet been able to find an answer to the following question:

I need:

  • a PDF
  • a title page
  • the table of contents starting on the second page
  • a page numbering starting at the table of contents
  • numbered sections
  • no automatic chapter numbering

I would like to do this without LateX code, bookdown or the import of any text files. Except for the last point, this seems to work with documentclass: report. Unfortunately I can't get rid of the chapters. Is there no pure rmarkdown YAML header solution for this?

---
title: The Force                                                                      
subtitle: May it be with you                                                                    
author: "Obi-Wan Kenobi"
date: "`r Sys.Date()`"
output: 
  pdf_document:
    toc: yes
    toc_depth: 3
    number_sections: true
documentclass: report
---
    
# Introduction
## Sub
### SubSub

# Methods
## Sub
### SubSub

CodePudding user response:

We can use "Chapter" removed


CodePudding user response:

If your only reason to use the report class is the page break before the table of contents, you could easily add it to the default class article:

---
title: The Force                                                                      
subtitle: May it be with you                                                                    
author: "Obi-Wan Kenobi"
date: "`r Sys.Date()`"
output: 
  pdf_document:
    keep_tex: true
    toc: yes
    toc_depth: 3
    number_sections: true
header-includes:
  - \pretocmd{\tableofcontents}{\clearpage}{}{}
  - \apptocmd{\tableofcontents}{\clearpage}{}{}
---
    
# Introduction
## Sub
### SubSub

# Methods
## Sub
### SubSub
  • Related