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!

2
  • 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}.
    – user31729
    Commented Nov 6, 2014 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
    Commented Nov 6, 2014 at 20:45

5 Answers 5

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

1
  • Wow, thanks! That explains why I haven’t been able to find any solutions for this. Commented Nov 7, 2014 at 15:29
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}
3
  • 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: pasteboard.co/K2bRQpp.png. Is there a proper way to "exactly" choose these values?
    – tobiasBora
    Commented May 16, 2021 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
    Commented May 18, 2021 at 12:03
  • @Keinstein Cool, thanks! I’ve upvoted your answer. Commented May 20, 2021 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}
2
  • It works nicely, but the new frames are added as new pages (different page number between slides...).
    – tobiasBora
    Commented May 16, 2021 at 16:51
  • Yes. This behaviour is the same as with Ignasi's accepted answer.
    – Keinstein
    Commented May 18, 2021 at 12:04
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}
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}[<+->]
        \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.

You must log in to answer this question.

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