rlatexr-markdownbeamer

Switching background in markdown beamer


I'm trying to transfer a LaTeX/LyX presentation into a Beamer markdown document.

On some slides I suspend the background image (which has logos of funding bodies on it) to make more space for code output.

I previously did this with the following command:

\bgroup
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{background.png}}
\begin{frame}[plain]
Some text here!}
\end{frame}
\egroup

I have tried something like this (which doesn't work):

\bgroup
\pgfdeclareimage[width=\paperwidth]{empty}{Template_blank.png}
\usebackgroundtemplate{\pgfuseimage{empty}}

## New Slide

some text
\egroup

Any ideas?


Solution

  • Normally switching between different background templates is a piece of cake in beamer, based on https://tex.stackexchange.com/questions/173201/beamer-template-with-different-style-options-for-frames one can simply create a new frame option.

    Unfortunately rmarkdown simply ignores user created frame options and only passes on a tiny list of predefined options. To trick rmarkdown one could repurpose a frame option which is normally not used by beamer, the standout frame option (it is only used by the moloch theme)

    ---
    output: 
      beamer_presentation:
        keep_tex: true
        includes:
    header-includes: |
      \usepackage{etoolbox}
    
      \defbeamertemplate{background canvas}{mydefault}{%
        \includegraphics[width=\paperwidth,height=\paperheight]{example-image-duck}
      }
      \defbeamertemplate{background canvas}{standout}{%
        \includegraphics[width=\paperwidth,height=\paperheight,page=2]{example-image-duck}
      }
    
      \BeforeBeginEnvironment{frame}{%
        \setbeamertemplate{background canvas}[mydefault]%
      }
    
      \makeatletter
      \define@key{beamerframe}{standout}[true]{%
        \setbeamertemplate{background canvas}[standout]%
      }
      \makeatother
    
    ---
    
    # frametitle 
    
    test
    
    # frametitle with different background {.standout}
    
    test
    
    # frametitle
    
    test
    

    enter image description here