6

I would like to use the slide backgrounds to illustrate the individual items of an itemize environment. However, the background image has to be specified outside the frame for all I know, and only, onslide, uncover, etc. don’t seem to work as expected there (the background is displayed on all slides for values equal 1 and hidden on all slides otherwise).

This is sort of how I’d like to use it, but it doesn’t work of course:

{
    \only<1>{\usebackgroundtemplate{\includegraphics[width=\paperwidth]{assets/background-01.png}}}%
    \only<2>{\usebackgroundtemplate{\includegraphics[width=\paperwidth]{assets/background-02.png}}}%
    \only<3>{\usebackgroundtemplate{\includegraphics[width=\paperwidth]{assets/background-03.png}}}%
    \frame{
        \frametitle{Promotion}
        \begin{itemize}[<+->]
            \item Identifying the target audience
            \item Understanding the target audience
            \item Identifying partners
         \end{itemize}
    }
}

Thank you!

  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Nov 06 '14 at 19:22
  • I had a similar problem and used TikZ to place a different background for each slide. However that needs some adjustments based on the theme, since the TikZ loaded background would cover the frame title and other outer elements (in my case the background was resized to not cover any theme-related element). – d-cmst Nov 06 '14 at 20:45

5 Answers5

3

I think what you want is not possible. Take a look at How does beamer build the frame? and will see that background canvas and background are constructed before anything else and the frame contents is the last piece, after titles and sidebars. Therefore even trying to supply a false background with TiKZ overlay and remember picture this background will cover any previous layer.

Next code shows a manual solution built playing with \visible and \invisible. You'll need to build as much as frames as items and if your slides are numbered, you'll need to find how to adjust them.

\documentclass{beamer}

\usepackage{mwe}

\begin{document}
\usebackgroundtemplate{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}
\begin{frame}{Promotion}
\begin{itemize}
\item\visible<1>{Identifying the target audience}
\item\invisible<1>{Understanding the target audience}
\item \invisible<1>{Identifying partners}
\end{itemize}
Some text
\end{frame}

\usebackgroundtemplate{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-b}}
\begin{frame}{Promotion}
\begin{itemize}
\item\visible<1>{Identifying the target audience}
\item\visible<1>{Understanding the target audience}
\item \invisible<1>{Identifying partners}
\end{itemize}
Some text
\end{frame}

\usebackgroundtemplate{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-c}}
\begin{frame}{Promotion}
\begin{itemize}
\item\visible<1>{Identifying the target audience}
\item\visible<1>{Understanding the target audience}
\item\visible<1>{Identifying partners}
\end{itemize}
Some text
\end{frame}

\end{document}

enter image description here

Ignasi
  • 136,588
2

Now I’ve also experimented with the solution below. It’s seriously hacky, but it’s more DRY, meaning it leads to less code duplication. There’s also no problem with frame numbers.

Many thanks to diabonas for the backgroundblock code.

\documentclass{beamer}

\usepackage{mwe}

% beamer: How to place images behind text (z-order)
% (https://tex.stackexchange.com/a/134311)
\makeatletter
\newbox\@backgroundblock
\newenvironment{backgroundblock}[2]{%
  \global\setbox\@backgroundblock=\vbox\bgroup%
    \unvbox\@backgroundblock%
    \vbox to0pt\bgroup\vskip#2\hbox to0pt\bgroup\hskip#1\relax%
}{\egroup\egroup\egroup}
\addtobeamertemplate{background}{\box\@backgroundblock}{}
\makeatother

\begin{document}

\begin{frame}{Promotion}
    \only<1>{
        \begin{backgroundblock}{-1mm}{0mm}
            \includegraphics[width=1.01\paperwidth]{example-image-a}
        \end{backgroundblock}
    }
    \only<2>{
        \begin{backgroundblock}{-1mm}{0mm}
            \includegraphics[width=1.01\paperwidth]{example-image-b}
        \end{backgroundblock}
    }
    \only<3>{
        \begin{backgroundblock}{-1mm}{0mm}
            \includegraphics[width=1.01\paperwidth]{example-image-c}
        \end{backgroundblock}
    }

    \begin{itemize}[<+->]
        \item Identifying the target audience
        \item Understanding the target audience
        \item Identifying partners
    \end{itemize}

    Some text
\end{frame}

\end{document}
  • Thanks for this solution, unfortunately the -1mm/width=1.01\paperwidth zooms the image a bit and shifts it by a few millimiters, and removing it adds ugly marings. For instance, here I put a screenshot of the slides as background: https://pasteboard.co/K2bRQpp.png. Is there a proper way to "exactly" choose these values? – tobiasBora May 16 '21 at 17:52
  • 2
    @tobiasBora this is an ugly hack to hide spaces that have been introduced at the line endings. I added an answer that provides better code. – Keinstein May 18 '21 at 12:03
  • @Keinstein Cool, thanks! I’ve upvoted your answer. – Dawn Drescher May 20 '21 at 20:29
1

This is easy to achieve with \againframe

\documentclass{beamer}
\begin{document}
\setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{background1}}
\begin{frame}<1>[label=ttt]{testframe}
\begin{itemize}
\item<+-> a
\item<+-> b
\item<+-> c
\item<+-> d
\end{itemize}
\end{frame}
\setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{background2}}
\againframe<2>{ttt}
\setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{background3}}
\againframe<3>{ttt}
\setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{background4}}
\againframe<4>{ttt}
\end{document}
Keinstein
  • 306
1

I adapted slightly this great answer, which "simply" does a test on \insertslidenumber to check the slide number in order to choose the appropriate usebackgroundtemplate. It works nicely with miniframes and page numbering, and does not zoom the image in unexpected ways. I'm not sure if it's great practice to mix \newcommand with ExplSyntax, but it works! (feel free to give better syntax in comments)

\documentclass[table,aspectratio=169]{beamer}

\useoutertheme[footline=institutetitle,subsection=false]{miniframes} \usecolortheme{beaver}

\ExplSyntaxOn \newcommand{\addBackgroundOne}[2]{ \bool_if:nT {\int_compare_p:n{\insertslidenumber=#1}}{% \includegraphics[width=\paperwidth,height=\paperheight]{#2} } } \newcommand{\addBackgroundSlice}[3]{ \bool_if:nT {\int_compare_p:n{\insertslidenumber>=#1} && \int_compare_p:n{\insertslidenumber<=#2}}{% \includegraphics[width=\paperwidth,height=\paperheight]{#3} } } \ExplSyntaxOff

\begin{document}

{ \usebackgroundtemplate{% \addBackgroundOne{1}{example-image-a} \addBackgroundSlice{2}{3}{example-image-b} \addBackgroundOne{4}{example-image-c} } \begin{frame} \begin{itemize} \item A \pause \item B \pause \item B \pause \item C \end{itemize} \end{frame} }

\end{document}

tobiasBora
  • 8,684
1

I'd like to add a corrected version of the answer from @Denis Drescher

\documentclass{beamer}

\usepackage{mwe}

% beamer: How to place images behind text (z-order) % (https://tex.stackexchange.com/a/134311) \makeatletter \newbox@backgroundblock \newenvironment{backgroundblock}{ \global\setbox@backgroundblock=\vbox\bgroup% \unvbox@backgroundblock% \vbox to0pt\bgroup\hbox to0pt\bgroup% \ignorespaces }{\egroup\egroup\egroup} \addtobeamertemplate{background}{\box@backgroundblock}{} \makeatother

\begin{document}

\begin{frame}{Promotion} \only<1>{ \begin{backgroundblock} \includegraphics[width=\paperwidth]{example-image-a} \end{backgroundblock} } \only<2>{ \begin{backgroundblock} \includegraphics[width=\paperwidth]{example-image-b} \end{backgroundblock} } \only<3>{ \begin{backgroundblock} \includegraphics[width=\paperwidth]{example-image-c} \end{backgroundblock} }

\begin{itemize}[&lt;+-&gt;]
    \item Identifying the target audience
    \item Understanding the target audience
    \item Identifying partners
\end{itemize}

Some text

\end{frame}

\end{document}

The problem was that the spaces at the before the background image were not ignored. I'm not convinced that this code works in all circumstances. In any case you cann add % signs after the braces in ordet to prevent latex from treating the newlines as spaces.

Keinstein
  • 306