latexr-markdowntableofcontentsbeamer

Rmd: Add numbered TOC in Beamer slides with metropolis theme


I am creating a RMarkdown template of Beamer slides and use the metropolis theme as a basis.

Now, I want a numbered table of content, which I was able to implement by the toc.tex. But when I include it here

beamer_presentation:
  includes:
    in_header:
      - toc.tex

the whole formatting of the slides disappears, which I do not want. How can I keep the formatting of the slides & get a numbered TOC

This is my (minimal working example):


slides.rmd:

---
title: "Title"
subtitle:  "Subtitle"
author: "Simon"
institute: "RUB"
date: "September 22, 2021"

output:
  beamer_presentation:
    keep_md: true
    keep_tex: no
    latex_engine: xelatex
    #theme: metropolis
    includes:
      in_header:
          - toc.tex
    slide_level: 2 # which header level should be printed as slides
    incremental: no
header-includes:
  - \usetheme[numbering=fraction]{metropolis}
  - \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
  - \setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021}}}
  - | 
    \makeatletter
    \def\ps@titlepage{%
      \setbeamertemplate{footline}{}
    }
    \addtobeamertemplate{title page}{\thispagestyle{titlepage}}{}
    \makeatother
---

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


## Content
\tableofcontents[]

# Level I

Test

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

# Slide with R Output

```{r cars, echo = TRUE}
summary(cars)
```

toc.tex:

\setbeamertemplate{section in toc}[sections numbered]
\setbeamertemplate{subsection in toc}[subsections numbered]

Solution

  • You can add \include{toc} to your header-includes:

    ---
    title: "Title"
    subtitle:  "Subtitle"
    author: "Simon"
    institute: "RUB"
    date: "September 22, 2021"
    
    output:
      beamer_presentation:
        keep_md: true
        keep_tex: true
        latex_engine: xelatex
        slide_level: 2 # which header level should be printed as slides
        incremental: no
    header-includes:
      - \usetheme[numbering=fraction]{moloch}
      - \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
      - \setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021}}}
      - | 
        \makeatletter
        \def\ps@titlepage{%
          \setbeamertemplate{footline}{}
        }
        \addtobeamertemplate{title page}{\thispagestyle{titlepage}}{}
        \makeatother
        \include{toc}
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = FALSE)
    ```
    
    
    ## Content
    \tableofcontents[]
    
    # Level I
    
    Test
    
    ## Slide with Bullets
    
    - Bullet 1
    - Bullet 2
    - Bullet 3
    
    # Slide with R Output
    
    ```{r cars, echo = TRUE}
    summary(cars)
    ```
    

    enter image description here