4

I want to highlight an entire slide in a presentation I am creating in R markdown, much in the same way as was done in this answer (without using markdown).

Cannot seem to figure it out though. Below is a dummy example of my failure so far...

---
title: "Untitled"
output: beamer_presentation
---

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

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

% \setbeamercolor{background canvas}{bg=red}

## Slide with R Output 

\setbeamercolor{background canvas}{bg=red}

```{r cars, echo = TRUE}
summary(cars)
```
  • Does colortheme: "dolphin" work? (Reference: this website.) – heather Aug 14 '16 at 12:41
  • @heather only to change the whole set of slides, not a specific slide – gjabel Aug 14 '16 at 13:57
  • Okay, sorry, I'll keep looking. – heather Aug 14 '16 at 13:58
  • throws a pandoc error. – gjabel Aug 14 '16 at 14:11
  • yeah, I made a mistake with that last one, that's why I deleted it (that was normal LaTeX, not R markdown...sorry). I'm still looking – heather Aug 14 '16 at 14:12
3

I created a key, bgcolor, that can be passed as an option to a frame. In the example below, only the second slide has a red background.

\documentclass{beamer}

\makeatletter
\define@key{beamerframe}{bgcolor}[]{%
  \ifx#1\@empty\else
    \def\ps@navigation@colored{%
      \setbeamercolor{background canvas}{bg=#1}%  background color
      \@nameuse{ps@navigation}}
    \thispagestyle{navigation@colored}
  \fi}
\makeatother


\begin{document}

\begin{frame}
  Test
\end{frame}


\begin{frame}[bgcolor=red]
  Test
\end{frame}


\begin{frame}
  Test
\end{frame}

\end{document}
1

As a workaround, you could hardcode for which frame number the background colour should be changed. This can be done in the preamble.

\documentclass{beamer}

\setbeamertemplate{background}{%
    \if\insertframenumber2
        \color{red}\rule{\paperwidth}{\paperheight}
    \fi
}

\begin{document}

\begin{frame}
    abc
\end{frame} 

\begin{frame}
    abc
\end{frame} 

\begin{frame}
    abc
\end{frame} 

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.