[Tex/LaTex] Beamer: Strange behavior when changing background color

beamercolor

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?

Best Answer

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}