93

How can I change the background color of one frame in my Beamer document? I tried doing

\begin{frame}
  \setbeamercolor{background canvas}{bg=violet}
  % frame contents here
\end{frame}

but it seemed to have no effect.

Anyone know what the problem is?

3 Answers 3

94

Modify the background canvas before you begin the frame, not within the frame.

To keep the effect of the color change local, you could use curly braces around the frame and that command, or \begingroup ... \endgroup.

{
\setbeamercolor{background canvas}{bg=violet}
\begin{frame}
  % frame contents here
\end{frame}
}
5
  • 10
    @Stefan, I tried to do as you said, but the color stay the same as previous slides. Do you know why it could possibly not work?
    – damluar
    Mar 15, 2013 at 20:39
  • @damluar It works for me. You probably made a mistake. Alternatively, instead of using \begingroup ... \endgroup, you may also simply use brackets { ... }. Nov 14, 2017 at 22:13
  • 2
    No, he didn't make a mistake. I took the exact code posted here and it doesn't work for me either.
    – pmaen
    Jan 28, 2023 at 12:34
  • @pmaen Your own document around that code is probably different. This code still works for me, I tested it again right now, and it worked for Ricardo, and Alan's answer shows the same approach in a complete small document. You can try that. If it doesn't work in your document, perhaps show the complete code as a minimal working example in a fresh question, with class options, beamer theme, etc.
    – Stefan Kottwitz
    Jan 28, 2023 at 14:25
  • 1
    I am guessing that the discrepancy is caused by @pmaen and @damluar using a document with the ignorenonframetext option set. To work around this, enclose the \setbeamercolor line with \mode<all>{...} Jun 26, 2023 at 13:42
31

Put the \setbeamercolorcommand outside the frame. This will change the background colour for every subsequent frame. If you want to just change that slide, you can surround the frame and the command in {}

Here's a complete example:

\documentclass{beamer}
\begin{document}
\begin{frame}{A white frame}
\end{frame}
% Change all subsequent frames to violet
\setbeamercolor{background canvas}{bg=violet!20}
\begin{frame}{A violet frame}
\end{frame}
\begin{frame}{This frame is also violet}
\end{frame}
% But this frame only will be yellow: note { ... } around
% the \setbeamercolor and the frame to limit the scope 
{\setbeamercolor{background canvas}{bg=yellow!20}
\begin{frame}{This frame is yellow}
\end{frame}
}
\begin{frame}{Subsequent frames will be violet}
\end{frame}
\end{document}

output of code

0
16

Here's a suggestion to add a bg option to the frame environment, such that background color can be invoked simply by adding the [bg] option to frame.

I have not tested this beyond the template below, put together by piecing random clues here and there. Making the actual color an argument, as in [bg=blue], is left as an exercices to the bored reader.

    \documentclass{beamer}

    \defbeamertemplate*{background canvas}{mydefault}
    {%
      \ifbeamercolorempty[bg]{background canvas}{}{\color{bg}\vrule width\paperwidth height\paperheight}% copied beamer default here
    }

    \defbeamertemplate*{background canvas}{bg}
    {%
      \color{lightgray!40}\vrule width\paperwidth height\paperheight% added bg color
    }

    \BeforeBeginEnvironment{frame}{%
      \setbeamertemplate{background canvas}[mydefault]%
    }

    \makeatletter
    \define@key{beamerframe}{bg}[true]{%
      \setbeamertemplate{background canvas}[bg]%
    }
    \makeatother

    \begin{document}

    \begin{frame}
    \frametitle{Normal}
    \end{frame} 

    \begin{frame}[bg]
    \frametitle{With bg}
    \end{frame}

    \begin{frame}
    \frametitle{Normal}
    \end{frame}

    \end{document}

enter image description here

enter image description here

A similar thing (going off topic now) can be done with an image, instead of plain color:

\documentclass{beamer}
\usepackage{graphicx}
\usepackage{tikz}

\pgfdeclareimage[width=\paperwidth]{mybackground}{brain}
%% As an option to frame
\defbeamertemplate*{background canvas}{mydefault}
{%
  \ifbeamercolorempty[bg]{background canvas}{}{\color{bg}\vrule width\paperwidth height\paperheight}% copied beamer default here
}
\defbeamertemplate*{background canvas}{image}
{%
    \begin{tikzpicture}
        \useasboundingbox (0,0) rectangle (\the\paperwidth, \the\paperheight); 
        \pgftext[at=\pgfpoint{0cm}{0cm}, left, base]{\pgfsetfillopacity{0.1}\pgfuseimage{mybackground}}; 
    \end{tikzpicture}
}
\BeforeBeginEnvironment{frame}{%
  \setbeamertemplate{background canvas}[mydefault]%
}
\makeatletter
\define@key{beamerframe}{image}[true]{%
  \setbeamercovered{invisible}%
  \setbeamertemplate{background canvas}[image]%
}
\makeatother%


\title[...]{My title}

\begin{document}

\begin{frame}[image]
    \titlepage
\end{frame}

\section{Introduction}

\begin{frame}[plain]
Text here
\end{frame}

\end{document}

enter image description here

1
  • 1
    This is very much what I was looking for. Notice that the choice of color for the example is not showing any difference in my (probably not very good graphic-wise) system, but with lightgray!80 instead of lightgray!40 the example works perfectly
    – Dalker
    Jan 31, 2022 at 8:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .