0

I'm trying to put \only<1>{...} images in the background slide of beamer. However, I need to add +1 to all values in \only, i.e. I need to write \only<2>{...} to display the image on the first frame. Despite being not practical, the problem is that it also duplicate the last slide 2 times, which creates without any reason an additional, unwanted slide...

Any reason for that? How can I come back to normal numbering, and remove this last unwanted frame?

Thanks!

MWE:

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

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

\begin{document}

{\usebackgroundtemplate{% % Why do I need to add 1 to get the correct value for only, and how can I remove the last, doubled, slide? \only<2>{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}% \only<3>{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-b}}% \only<4>{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-c}}% } \begin{frame}[t] \begin{itemize} \item \onslide<1>{A} \item \onslide<2>{B} \item \onslide<3>{C (see that on the next slide there is an empty slide...)} \end{itemize} \end{frame} }

\end{document}

enter image description here

-- EDIT -- The problem of the solution given in this thread is that it create additional pages instead of putting all slides in a single page...

\documentclass{beamer}

\useoutertheme[footline=institutetitle,subsection=false]{miniframes} \usecolortheme{beaver} \setbeamercolor{separation line}{use=structure,bg=darkred!80!black}

\begin{document} \section{test}

{ \setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{example-image-a}} \begin{frame}<1>[label=myframelabel] \begin{itemize} \item<+-> a \item<+-> b \item<+-> c \item<+-> d \item<+-> e \end{itemize} \end{frame} \setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{example-image-b}} \againframe<2>{myframelabel} \setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{example-image-c}} \againframe<3>{myframelabel} \setbeamertemplate{background}{\includegraphics[height=\paperheight,width=\paperwidth]{example-image-a}} \againframe<4->{myframelabel} }

\begin{frame} Hello, I'm a new empty frame \end{frame} \end{document}

tobiasBora
  • 8,684

2 Answers2

2

you are overdoing with the \only in the background template. You can simply retrieve the slide number and choose your graphic based on its value:

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

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

\begin{document}

\ExplSyntaxOn \usebackgroundtemplate{% \tl_set:Nx \l_tmpa_tl {example-image-\int_to_alph:n{\insertslidenumber}} \includegraphics[width=\paperwidth,height=\paperheight]{\l_tmpa_tl}} \ExplSyntaxOff
\begin{frame}[t] \begin{itemize} \item \onslide<1>{A} \item \onslide<2>{B} \item \onslide<3>{C (see that on the next slide there is an empty slide...)} \end{itemize} \end{frame}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Thanks a lot, it works great! I also added a new answer that improves slighly the readability of the code and that allows ranges like <1-3> (I used newcommand, I'm not sure if it's great to mix that with ExplSyntax, but at least it seems to work nicely). – tobiasBora May 17 '21 at 08:08
0

After Ulrich's answer, I came out with this code to also handle ranges like <4-5>, and to factorize a bit the repetitive code. So I don't bring any new idea, but I just wanted to provide it for reference. I'm not sure if it's great practice to mix newcommand with ExplSyntax... but it seems to really nicely, thanks a lot! It also works with miniframes, pages...

\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}[t] \begin{itemize} \item A \pause \item B \pause \item B \pause \item C \end{itemize} \end{frame} }

\end{document}

tobiasBora
  • 8,684