Search code examples
rr-markdownbeamer

Add left sidebar to Beamer Presentation in R Markdown


I am using R Markdown to knit to a Beamer presentation.

My presentation includes a table of contents. I would like the TOC to be visible as a left-handed sidebar throughout the presentation. Preferentially I would like the current section to be highlighted.

Is it possible to do this directly in R, or do I have to wrangle with intermediate Latex output? I think it may be possible with a Pandoc template, if so, how do I get to this solution?


Solution

  • You can set the outertheme: sidebar option in the YAML. This gets passed to the pandoc template intro \useoutertheme{} option. You can see the pandoc template used here if you are interested to see what other things can be set by the frontmatter.

    Here is a minimal example:

    ---
    title: "Habits"
    author: John Doe
    date: March 22, 2005
    output: beamer_presentation
    outertheme: sidebar
    ---
    
    # In the morning
    
    ## Getting up
    
    - Turn off alarm
    - Get out of bed
    
    ## Breakfast
    
    - Eat eggs
    - Drink coffee
    
    # In the evening
    
    ## Dinner
    
    - Eat spaghetti
    - Drink wine
    
    ----
    

    As you can see from the output, the sidebar changes the highlighting depending on the page:

    enter image description here

    If you want to show the title of each slide on the sidebar (i.e. Breakfast, In the evening), you have to alter the slide_level variable in the YAMl:

    output: 
      beamer_presentation:
        slide_level: 3