5

Using \setbeamercolor{background canvas}{bg=black} works fine if I want to change the background color. However once I used \setbeamertemplate{background canvas}{} it doesn't work anymore:

\documentclass{beamer}

\begin{document}

% as expected

\begin{frame}{Test}
white
\end{frame}

\setbeamercolor{background canvas}{bg=black}
\begin{frame}{Test}
\textcolor{white}{black}
\end{frame}

\setbeamercolor{background canvas}{bg=}
\begin{frame}{Test}
white again
\end{frame}

% confusing

\setbeamertemplate{background canvas}{}
\setbeamercolor{background canvas}{bg=black}
\begin{frame}{Test}
should be black
\end{frame}

\end{document}

EDIT: Why do I do this?

I sometimes use a code like this

\setbeamertemplate{background canvas}{\includegraphics[width=\paperwidth]{picture.jpg}}

to use a picture to fill the background. I clear the picture by using

\setbeamertemplate{background canvas}{} 

How else could I clear the picture?


Ok:

enter image description here

Ok:

enter image description here

Ok:

enter image description here

Here's the mistake:

enter image description here

Any ideas?

  • 1
    AFAIK a Beamer template is some LaTeX code. The default template code for background canvas surely has \usebeamercolor{background canvas} or equivalent in it. So if you set the template to empty, the color will never get used. – marczellm Jan 11 '14 at 19:28
4

Andrew Swann's answer explains why this happens but I thought you might find it useful to see what you might want to do instead. I'm not sure what you are trying to achieve by setting the template to empty but it may be that you really just wanted to eliminate the headline/footline etc. so that the entire area of the slide was available for content. I've therefore modified your example a little to show some of the possibilities:

\documentclass{beamer}

\begin{document}

% as expected

\begin{frame}{Test}
white
\end{frame}

\setbeamercolor{background canvas}{bg=black}
\begin{frame}{Test}
\textcolor{white}{black}
\end{frame}

\setbeamercolor{background canvas}{bg=}
\begin{frame}{Test}
white again
\end{frame}

% confusing

\setbeamercolor{background canvas}{bg=black}
\begin{frame}[plain]{Test}
Perhaps you just wanted to use a \texttt{plain} frame rather than eliminating the background altogether.
\end{frame}

\setbeamertemplate{background canvas}{}
\setbeamercolor{background canvas}{bg=red}
\begin{frame}{Test}
As others have explained, the template is now completely empty so the colour specification has no effect.
\end{frame}


\setbeamertemplate{background canvas}[default] % <--- Important

\begin{frame}{Test}
Now the template is reset to default, the colour specification earlier changes the background to red.
\end{frame}

\end{document}
  • Thanks. I added information to the question why I used \setbeamertemplate{background canvas}{}. – Dr. Manuel Kuehner Jan 12 '14 at 0:43
  • @ManuelKuehner Note that my code answers your edited question. Look at \setbeamertemplate{background canvas}[default] before the last frame and notice that it restores the default template which means the colour specification affects the final frame, even though it did not affect the preceding one. (The last frame is red; the one before is white.) – cfr Jan 12 '14 at 0:51
  • Great! Thanks. I had this problem for literally years. – Dr. Manuel Kuehner Jan 12 '14 at 6:24
5

The beamer template background canvas is the code for making the background. By default it is

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

As you see it includes code that uses the key bg. Your command

\setbeamertemplate{background canvas}{}

removes this code, and now the option bg is not used, so has no effect.

  • Thanks. I added information to the question why I used \setbeamertemplate{background canvas}{}. – Dr. Manuel Kuehner Jan 12 '14 at 0:41
  • Is it important that it's the starred version? – Dr. Manuel Kuehner Jan 12 '14 at 13:22

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.