0

I try to animate something moving on a slide. I am using the packages pgfplots and animate to achieve this. Here is an example:

\documentclass[aspectratio=1610]{beamer}
\setbeamertemplate{navigation symbols}{}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{animate}

\newcommand{\Textfield}[3]{%
    \draw%
        (current page.south west) ++(#1,#2)node[anchor=south west](N0){#3}%
    ;%
}%

\begin{document}
\begin{frame}
\begin{tikzpicture}[remember picture,overlay]%
    \useasboundingbox (current page.south west) rectangle (current page.north east);%
    \Textfield{1cm}{1cm}{Moving Text}
\end{tikzpicture}
\end{frame}
\begin{frame}
\begin{animateinline}[autoplay,controls=all,%
        begin={\begin{tikzpicture}[remember picture]%,overlay
        \useasboundingbox (current page.south west) rectangle (current page.north east);},%
        end=\end{tikzpicture}]{20}%
    \multiframe{61}{dPosTy=10mm+1mm}%
    {\Textfield{1cm}{\dPosTy}{Moving Text}}%
\end{animateinline}%
\end{frame}
\end{document}

In my result, I get an offset in the text position in the animation. If I use the overlay option in the animation, I even get two errors:
'Contents of first frame must not have zero width'
'Contents of first frame must not have zero height'
Can anyone explain, why that is and how to to it correctly?
Thank you in advance

3
  • Do you want a line draw from current page.south west to the south west anchor of Moving Text?
    – AlexG
    Mar 23 '20 at 20:47
  • Note that the animation controls are below the lower page edge and therefore invisible if the animation has the same dimensions as the slide.
    – AlexG
    Mar 23 '20 at 20:50
  • Thanks for the comments. I do not want to draw a line. I would like to make "moving text" move from the coordinates (1cm,1cm) to a different location. unfortunately, when I compile, it starts not at (1cm,1cm), but about 1cm to the right. I am aware that the controls are not visible on the slide. They just give the opportunity to rewind to starting position, so we can compare the starting position wit previous slide.
    – CyberianS
    Mar 24 '20 at 7:11
0

If tikzpicture's overlay option is used, the resulting TeX box has zero dimensions. This is not allowed inside the animateinline environment, because the animation widget's width, height and depth are determined from the first frame's dimensions. If they are zero, the widget size would be zero too, which doesn't make sense. This is the reason for the error message you get.

I'd suggest the following solution. The (slide-filling) animation is typeset into an lrbox first, in order to avoid nesting tikzpicture environments (which is considered deprecated practice). The lrbox can then be placed absolutely, using the page node current page.

\documentclass[aspectratio=1610]{beamer}
\setbeamertemplate{navigation symbols}{}

\usepackage{animate}

\usepackage{tikz}
%\usepackage{pgfplots} % not used here
%\pgfplotsset{compat=newest}

\newsavebox\animation

\newcommand{\Textfield}[3]{\node[anchor=south west, draw] at (#1,#2) {#3};}%
%\newcommand{\Textfield}[3]{\draw (0,0) -- (#1,#2) node[anchor=south west, draw] {#3};}%

\begin{document}

\begin{lrbox}{\animation}
  \begin{animateinline}[
    autoplay,controls,
    begin={\begin{tikzpicture}
      \useasboundingbox (0,0) rectangle (\paperwidth,\paperheight);},
    end=\end{tikzpicture}
  ]{20}
    \multiframe{61}{dPosTy=10mm+1mm}{\Textfield{1cm}{\dPosTy}{Moving Text}}
  \end{animateinline}
\end{lrbox}

\begin{frame}
  \begin{tikzpicture}[overlay,remember picture]
    \node [inner sep=0pt, outer sep=0pt, anchor=base west] at (current page.south west) {\usebox\animation};
  \end{tikzpicture}
\end{frame}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.