5

This is a follow-up question from Zooming effect for scientific figures in beamer.

The minimal working example below needs three figures named "fig_1.pdf", "fig_2.pdf" and "fig_3.pdf" in the same directory as the tex file.


Essentially I use a tikz-picture and overlays to include multiple figures at the same location exactly on top of each other. This is supposed to create the effect of clicking through different figures in the presentation.

In addition, I use \animategraphics[<options>]{<frame rate>}{<file basename>}{<first>}{<last>} from the animate package to create a smooth transition between two such figures via multiple other figures.

The problem is that even though the animation is only supposed to appear on the second slide (since it is surround by \onslide<2>), when compiling it appears on every slide and the other figures can't be seen at all. The overlays for the itemize bits seem to work correctly though.

Is this a bug? Or am I doing something wrong?

\documentclass{beamer}

\usetheme{boxes}

\usepackage[export]{adjustbox}

\usepackage{tikz,animate}
\usetikzlibrary{shapes,arrows,positioning}
\usetikzlibrary{decorations.pathreplacing,angles,quotes,decorations.pathmorphing}

\begin{document}
    \begin{frame}{Hello}
        \framesubtitle{I like trains}
        \begin{itemize}
            \item<1-> Hello1
            \item<2-> Hello2
        \end{itemize}
        \begin{columns}
            \column{0.5\linewidth}
            \centering
            \begin{tikzpicture}
            \onslide<1->{
                \draw[<->] (-0.8,0) -- (0.8,0);
            }
            \end{tikzpicture}
            \column{0.5\linewidth}
            \begin{tikzpicture}[]
            \onslide<1>{
                \node at (0,0) {
                    \includegraphics[width=0.95\textwidth]{example-image-a}
                };}
            \onslide<2>{
                \node at (0,0) {
                    \animategraphics[width=0.95\textwidth,autoplay,every=1]{100}{"fig_"}{1}{3}
                };}
            \onslide<3>{
                \node at (0,0) {
                    \includegraphics[width=0.95\textwidth]{example-image-b}
                };}
            \onslide<4-5>{
                \node at (0,0) {
                    \includegraphics[width=0.95\textwidth]{example-image-a}
                };}
            \onslide<6>{
                \node at (0,0) {
                    \includegraphics[width=0.95\textwidth]{example-image-b}
                };}
            \end{tikzpicture}
        \end{columns}
        \only<1-5>{
            \uncover<5>{
                Conclusion 1
            }
        }
        \only<6>{
            \uncover<6>{
                Conclusion 2
            }
        }
    \end{frame}
\end{document}

1 Answers1

9

Use \only instead of \onslide for the problematic command.


The major difference between the two (basically, between \only and all other overlay commands) is the following:

  • \only throws away its argument on the slides not given by the overlay specification. That is, tex does not even see what has been passed to \only.
  • \onslide, \alt, \uncover, ... still evaluate what has been given to them (typeset it inside a box), but throw away the result.

Both yield similar results with simple content. If, however, the commands to be executed do cause side effects, \onslide causes these side effects to happen also on the slides excluded by the overlay specification, while \only prevents this.

"Side effects" are basically any result of a command that escapes the current scope and box. I assume \animate fiddles directly with the PDF level. Other examples include TikZ trickery with overlay and remember picture (e.g., the famous \tikzmark command).

Daniel
  • 37,517