13

I am writing a beamer presentation in rmarkdown and converting it to pdf with knitr. I want to define sections at the header1 level, e.g. # Introduction, and then have a slide titled something else e.g. ## Introducing my brilliant research. Having the header1 level define sections is nice as the names of the sections can be displayed in the slide header in certain beamer themes, and this is why I include it.

But I do not want rmarkdown to insert a slide that simply says the name of the section between sections, which at the moment it is doing. Is there a way to not print a slide with the section name between sections? I thought slide_level would control this behavior but it does not seem to (or perhaps I am using it wrong).

A minimal reproducible example of my problem can be obtained with this code:

---
title: "Test Pres"
author: "Professor Genius Researcher"
date: "24 February 2017"
output: 
  beamer_presentation:
    slide_level: 2
    theme: "Singapore"
    colortheme: "rose"
---

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

# Markdown Intro

## R Markdown

This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

# Using Bullets

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

# Including Chunks

## Slide with R Output

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

## Slide with Plot

```{r pressure}
plot(pressure)
```

At the moment, this code produces slides that say Markdown Intro, Using Bullets, and Including Chunks. I would like those slides labeling the sections omitted. Is this possible?

gfgm
  • 3,627
  • 14
  • 34
  • Used `slide_level: 1`? Is this solving your problem? – J_F Feb 24 '17 at 13:33
  • no that makes the section title the title of the slide and puts all the subsequent slides into text boxes underneath it – gfgm Feb 24 '17 at 13:36
  • Is removing the space after the header1 not what you had in mind either? – Ryan Morton Feb 24 '17 at 16:00
  • See [LaTeX Beamer prevent showing the TOC](http://stackoverflow.com/questions/2795478/latex-beamer-prevent-showing-the-toc-at-one-occation), I tried replacing `# Including Chunks` with `\section*{Including Chunks}` but latex-engine pdflatex returns an error `! Missing \endgroup inserted.` – Paul Rougieux Feb 24 '17 at 16:13
  • See also the [Rmarkdown help on advanced PDF customization](http://rmarkdown.rstudio.com/pdf_document_format.html#advanced-customization). – Paul Rougieux Feb 24 '17 at 16:20

1 Answers1

11

Create a new Latex template where you remove this part from the preamble:

\AtBeginSection[]
{
  ....
}

Place this latex template in the same folder as your .Rmd file and refer to it in the Rmd Yaml front matter using template: mytemplate.tex as explained here.

Community
  • 1
  • 1
Paul Rougieux
  • 10,289
  • 4
  • 68
  • 110
  • 2
    Brilliant. Many thanks indeed. One small change: the template file suggested via your link doesn't seem to cover beamer. I couldn't find the default beamer template on my system, so I got it [here](https://github.com/jgm/pandoc-templates/blob/master/default.beamer) and did the edit as you suggested. – gfgm Feb 24 '17 at 17:00
  • The template link above is broken, as the `default_beamer` template seems to be merged to [`default_latex`](https://github.com/jgm/pandoc-templates/blob/master/default.latex). At least, `default_latex` works for me. – SaschaH Jul 26 '18 at 10:16
  • 3
    Modifying YAML header with `header-includes: - \AtBeginSection{}` is also a viable option. Please see https://stackoverflow.com/questions/38180441/dropping-frames-of-sections-and-subsections-titles-for-knitr-beamer-slides – Matthew Son Jun 23 '21 at 00:36