3

I want to achieve a simple "fly-in"-animation with LaTeX by utilizing the animate-package. My idea was to insert an \hspace with decreasing length-argument. However, there is no animation at all.

MWE (adapted from http://texample.net/tikz/examples/animated-definite-integral/):

\documentclass{beamer}

\usepackage{animate, ifthen}

\newcounter{m}
\setcounter{m}{0}

\newlength{\dummy}
\setlength{\dummy}{8cm}

\begin{document}
    \begin{frame}[fragile]
        \begin{animateinline}{2}
            \whiledo{\them < 21} {  % Execute 21 times
                \hspace{\dummy} Hello.
                \addtolength{\dummy}{-.4cm} % Decrease \dummy
                \stepcounter{m}
                \ifthenelse{\them < 21} {
                    \newframe % Create new frame, if condition satisfied
                }{
                    \end{animateinline}\relax % Otherwise end environment
                }
            }
    \end{frame}
\end{document}

Maybe i should just use TikZ to modify coordinates/parameters like this, but i initially thought, this should work and would be a more minimal way to achieve my goals.

Why isn't this working? What would be a better approach if mine was wrong?

1 Answer 1

7

Using \whiledo for building loops around parameterized animation frames is deprecated. It may lead to unexpected results, because \newframe embedded into its loop body may hide local assignments of dimensions and counters.

Instead, use pkg animate's built-in command \multiframe:

\documentclass{beamer}

\usepackage{animate}

\begin{document}
  \begin{frame}{Fly-in example}
    \begin{animateinline}[autoplay]{20}
      \multiframe{21}{dim=8cm+-0.4cm}{
        \makebox[\widthof{\hspace{8cm}Hello.}][l]{\strut\hspace{\dim}Hello.}
      }
    \end{animateinline}
  \end{frame}
\end{document}

enter image description here

2
  • Thank you very much! That's what i hoped to achieve. Also thanks for the pointer of \whiledo being deprecated. I didn't know that!
    – Tim Hilt
    Feb 10, 2020 at 11:45
  • @Tim I added a bit of explanation.
    – AlexG
    Feb 10, 2020 at 12:18

You must log in to answer this question.

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