# Make a slide background optional in Beamer [duplicate]

I've got a background in my custom template which I'd like to be able to switch off for certain slides. Ideally I'd do this with an option to \begin{frame}. My template is very loosely based on the approach in Claudio Fiandrino's answer to "Design a custom Beamer theme from scratch".

I've seen How to insert a background image in a beamer frame? and How to include a background image to only one page of a beamer presentation?; what I'm looking for is essentially the reverse of the latter, but cleanly (if I get this template right I won't be the only one using it so I wan't it to be robust).

This ends up being quite a lot of code just for an MWE. The most relevant bit is probably first, in beaminnerthemecf.sty:

\mode<presentation>

\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox[inner sep=0] (0,0) rectangle(\paperwidth,\paperheight);
\node[anchor=north,opacity=0.25] (bkg) at (current page.north) {\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}};
\fill[color=red,anchor=north west] (0,\the\paperheight) rectangle(\the\paperwidth,0.85\paperheight);
\node[anchor= south east, red,align=right] at (0.975\paperwidth,0.025\paperheight){\normalsize\insertauthor\\[0.2em]\normalsize\insertdate};
\ifnum\thepage>1\relax%
\ifx\insertframesubtitle\@empty%
{\node[anchor=north west, white,font=\Large] at (0.025\paperwidth,0.975\paperheight){\insertframetitle};}
\else{%
\node[anchor=north west, white,font=\Large] at (0.025\paperwidth,0.985\paperheight){\insertframetitle};%
\node[anchor=north west, white,font=\large] at (0.025\paperwidth,0.925\paperheight){\insertframesubtitle};%
}%
\fi
\fi
\end{tikzpicture}
}

% Title page
\defbeamertemplate*{title page}{cf}[1][]{%
\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)}]
\useasboundingbox (current page.south west) rectangle(\paperwidth,\paperheight);
\node[anchor=center, red,inner sep=0,align=center,text width=0.8\paperwidth] at (0.5\paperwidth,0.5\paperheight){\inserttitle};
\end{tikzpicture}
}
% Items
\setbeamertemplate{items}[square]
\setbeamertemplate{sections/subsections in toc}[square]
\mode<all>


to test it we can compile dummy.tex:

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\title{\Large{\textbf{There Is No Largest Prime Number}}}
\date[ISPN ’80]{27th International Symposium of Prime Numbers}
\author[Euclid]{Euclid of Alexandria \texttt{euclid@alexandria.edu}}
\usetheme{cf}

\begin{document}

\begin{frame}
\titlepage
\end{frame}

\begin{frame} % This is where I'd like to turn off the background image
\frametitle{There Is No Largest Prime Number}
\framesubtitle{The proof uses \textit{reductio ad absurdum}.}
This is a test
\begin{enumerate}
\item Suppose $p$ were the largest prime number.
\item Let $q$ be the product of the first $p$ numbers.
\item Then $q+1$ is not divisible by any of them.
\item But $q + 1$ is greater than $1$, thus divisible by some prime
number not in the first $p$ numbers.
\end{enumerate}
\end{frame}

\end{document}


Also needed are beamerouterthemecf.sty:

\mode<presentation>
% Frame title
\defbeamertemplate*{frametitle}{cf}[1][]{
}
\mode<all>


and beamercolorthemecf.sty:

\mode<presentation>
% Settings
\setbeamercolor*{author}{fg=white}
\setbeamercolor*{date}{fg=white}
\setbeamercolor*{item}{fg=red}
\setbeamercolor*{normal text}{fg=black}
\mode<all>


## marked as duplicate by user36296, user13907, Zarko tikz-pgf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Aug 17 '16 at 21:30

• Maybe have a look at tex.stackexchange.com/questions/173201/…. This shows how to define custom frame options and return to the defaults. – user36296 Aug 17 '16 at 9:43
• @samcarter that looks good - I think I can cook something up based on the asnwer to your question – Chris H Aug 17 '16 at 11:18
• I agree with the duplicate. My searches didn't turn it up because I was fixated on images; so perhaps this question shoudl serve as a pointer. – Chris H Aug 18 '16 at 8:44

You can always declare a local empty background.

\documentclass{beamer}

\setbeamertemplate{background}{
\includegraphics[height=\paperheight,width=\paperwidth]{example-image-a}
}

\begin{document}

\begin{frame}
Background image
\end{frame}

{%-> Starts scope where to apply following template
\setbeamertemplate{background}{}
\begin{frame}
No background image
\end{frame}
}%-> Ends scope where particular template has been applied.

\begin{frame}
Background image, again.
\end{frame}

\end{document}


• That looks like the "right" way to do it, but in that case I'd have to find some other way to define the title bar, logo etc. I think I can see a way to do it based on the link samcarter put in the comments. – Chris H Aug 17 '16 at 11:11
• It's supposed that according beamer-way-of-doing Title bar, logo, etc are not part of background template – Ignasi Aug 17 '16 at 16:07