Search code examples
rr-markdownmarkdownbeamer

R markdown beamer slides: top align body text but center top-level section headings


I am using R Markdown to create slides for a beamer presentation. To align text to the top of the slide (rather than the default centering), I am using classoption: t in the yaml header.

The problem is that this also top aligns the section headings (i.e. the top-level headers that appear on their own slides). How do I stop this happening?

I found this answer, which includes (in a comment) the suggestion to use # New Slide {.t} if you want to apply the top alignment only to a particular slide. But I want it the other way round: top aligned everywhere except for the section headings.

Any ideas?

Here's a minimal example where the section headers are incorrectly top-aligned:

---
title: "Your Presentation Title"
author: "Your Name"
date: "`r Sys.Date()`"
output:
  beamer_presentation:
classoption: t
---

# Section 1

## Slide 1

Content here.

# Section 2

## Slide 2

More content here.

Solution

  • ---
    title: "Your Presentation Title"
    author: "Your Name"
    date: "`r Sys.Date()`"
    output:
      beamer_presentation:
    classoption: t
    header-includes:
     - \AtBeginSection{\ifbibliography\else\frame[c]{\sectionpage}\fi}
    ---
    
    # Section 1
    
    ## Slide 1
    
    Content here.
    
    # Section 2
    
    ## Slide 2
    
    More content here.