1

I am creating a presentation with Rstudio using knitr and I want to use the types of the slides to generate a table of contents slide in the beginning. So if I have the following code:

Some fun lecture
========================================================
author: some guy
date: in the future

Table of content slide
========================================================
Here I want the table of content based on the following slide types

Some stuff 1
========================================================
type:section
Some very important stuff

More detail on stuff 1
========================================================
type:subsection
Did not get enough of stuff 1!? Here is more :D

Stuff 2
========================================================
type:section
There are other kinds of stuff?

Prompt slide
========================================================
type:prompt
Do not display prompt or alert types in TOC

So basically I want a table of content slide after the title slide looking something like:

  • Some stuff 1
    • More detail on stuff 1
  • Stuff 2

Is this available by default or do I need some extra CSS style in the beginning to handle this?

Gumeo
  • 891
  • 1
  • 13
  • 26

1 Answers1

2

To generate a table of contents, include a document header with the option "toc:true" at the beginning of the document. Level 1 headings are indicated by #, level 2 headings by ##, and so on. Below is an example . The "prompt" option is only relevant for R code chunks. R code chunks are not listed in the table of contents.

This will, however, only produce a html document. If you want a Latex-like presentation with individual slides, you can replace html_document with beamer_presentation. In the beamer presentation, only level 1 headings are listed in the table of contents.

---
title: "Sample Document"
author: "Author"
output:
  html_document:
    toc: true
---

# Some stuff 1
Some very important stuff

## More detail on stuff 1
Did not get enough of stuff 1!? Here is more :D

# Stuff 2
There are other kinds of stuff?

```{r, prompt=TRUE}
summary(iris[, "Sepal.Length"])
```

For more info on Beamer presentations in Rmarkdown, see http://rmarkdown.rstudio.com/beamer_presentation_format.html. A similar question has been answered here.

toldo
  • 416
  • 3
  • 5