Rmd:在带有大都市主题的 Beamer 幻灯片中添加编号目录

Rmd: Add numbered TOC in Beamer slides with metropolis theme

我正在创建 RMarkdown Beamer 幻灯片 模板,并使用 metropolis 主题作为基础。

现在,我想要编号 table 的内容,我能够通过 toc.tex 实现。但是当我在这里包含它时

beamer_presentation:
  includes:
    in_header:
      - toc.tex

幻灯片的整个格式消失了,这是我不想要的。 如何保持幻灯片的格式并获得编号的目录

这是我的(最小工作示例):


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]

您可以将 \include{toc} 添加到您的 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
    #theme: metropolis
    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
    \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)
```