Search code examples
r-markdownbeamertableofcontents

RMarkdown Beamer TOC empty


Using beamer in RMarkdown for presentations, I can't figure out why the TOC is empty. I have tried using a MacBook and Windows.

---
title: "test"
author: "my name"
date: "12/6/2016"
output:
  beamer_presentation:
    keep_tex: true
    toc: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

# Slide 1
Slide content

# Slide 2
Slide content

Outputs the pdf presentation with a title slide, an empty page (where the TOC should be), and then the two slides.

On Windows platform:

> R.version

platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          3.1                         
year           2016                        
month          06                          
day            21                          
svn rev        70800                       
language       R                           
version.string R version 3.3.1 (2016-06-21)
nickname       Bug in Your Hair 

RStudio:0.99.896

Rmarkdown: 1.2

knitr: 1.15.1

Somewhat related question here: Table of content in beamer generated with R markdown/knitr

Using the keep_tex: true argument in the YAML, I see from the tex file that the level 1 headers (i.e. # Section) are not being properly converted to sections in the tex file. For example, from the tex file:

\begin{frame}{Slide 1}

Slide content

\end{frame}

It seems that RMarkdown is not making the tex file correctly.


Solution

  • As pointed out here, the TOC will list the sections (as defined by single #'s), and the slide level must be a level below the sections (defined below in the YAML as slide_level: 2 and in the presentation by ##'s). I don't completely understand why you can't have sections at the slide level, but at least this works.

    ---
    title: "test"
    author: "my name"
    date: "12/6/2016"
    output:
      beamer_presentation:
        keep_tex: true
        toc: true
        slide_level:2
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = FALSE)
    ```
    
    # Section 1
    
    ## Slide 1
    Slide content
    
    # Section 2
    
    # Slide 2
    Slide content