Search code examples
rlatexr-markdownbookdown

Move the table of content away from the title page in Rmarkdown / bookdown PDF


I would like to use the bookdown package to generate a pdf document:

---
title: "My Book"
date: "`r Sys.Date()`"
author: "Author"
output:
  bookdown::pdf_document2:
   keep_tex: true
   number_sections: true
---

\newpage
\tableofcontents
\newpage

# chapter 1

## section a
## section b

# chapter 2

## section a
## section b

Here the table of content will be right in the first page and the \newpage commands are ignored. How could I push the table of content into the next page ?

on the other hand, if I use the pdf_document as output the \newpage commands will work :

---
title: "My Book"
date: "`r Sys.Date()`"
author: "Author"
output:
  pdf_document:
   keep_tex: true
   number_sections: true
---

\newpage
\tableofcontents
\newpage

# chapter 1

## section a
## section b

# chapter 2

## section a
## section b

I need to use the bookdown version in order to do the tables and figures cross referencing.


Solution

  • The toc you see on the first page is not the one you inserted manually. It was automatically inserted. You can use the toc: false option to switch this off.

    ---
    title: "My Book"
    date: "`r Sys.Date()`"
    author: "Author"
    output:
      bookdown::pdf_document2:
       keep_tex: true
       number_sections: true
       toc: false
    ---
    
    \newpage
    \tableofcontents
    \newpage
    
    # chapter 1
    
    ## section a
    ## section b
    
    # chapter 2
    
    ## section a
    ## section b
    

    enter image description here