[Tex/LaTex] TikZ and animateinline

animatebeamertikz-pgf

I have 2 presentations:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
\usetikzlibrary{calc,intersections}
  \begin{frame}
    \begin{center}
      \begin{tikzpicture}
         \useasboundingbox (3,0.5) rectangle (7,4.5);
         \pause
         \draw [name path=circle, line width=1](5,2.5) circle (2);
         \pause
         \draw [name path=line, line width=1](2,1)--(7,4) ;
         \path [name intersections={of = circle and line}];
         \coordinate (A) at (intersection-1);
         \coordinate (B) at (intersection-2);
         \pause
         \filldraw(A) circle (1.5pt);
         \pause    
         \filldraw(B) circle (1.5pt);
      \end{tikzpicture}
    \end{center}
  \end{frame}
\end{document} 

and

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
\usetikzlibrary{calc}
   \begin{frame}
      \begin{animateinline}[autoplay]{90}
      \multiframe{121}{iAngle=0+3}
         {\begin{tikzpicture}
             \useasboundingbox (3,0.5) rectangle (7,4.5);
             \draw [line width=1](5,2.5) arc (0:\iAngle:2);
         \end{tikzpicture}}
      \end{animateinline}
   \end{frame}
\end{document} 

I want to combine it with all functionality. I do it this way:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
   \usetikzlibrary{calc,intersections}
   \begin{frame}
      \begin{center}
         \begin{tikzpicture}
            \useasboundingbox (3,0.5) rectangle (7,4.5);
            \pause
                  \begin{animateinline}[autoplay]{90}
                     \multiframe{121}{iAngle=0+3}
                     {\draw [line width=1](5,2.5) arc (0:\iAngle:2);}
                  \end{animateinline}
            \draw [name path=circle, line width=1](5,2.5) circle (2);
            \pause
            \draw [name path=line, line width=1](2,1)--(7,4) ;
            \path [name intersections={of = circle and line}];
            \coordinate (A) at (intersection-1);
            \coordinate (B) at (intersection-2);
            \pause
            \filldraw(A) circle (1.5pt);
            \pause    
            \filldraw(B) circle (1.5pt);
         \end{tikzpicture}
      \end{center}
   \end{frame}
\end{document} 

What am I doing wrong? And how can I do it right?

Best Answer

A TikZ \draw alone doesn't produce a box with non-zero width and height, but animateinline expects something of non-zero size in order to produce animation frames.

Therefore a tikzpicture environment must surround the graphical objects inside the animateinline environment (as in the standalone animation in the 2nd code box). But you removed it from the "combined" document (3rd code box). Hence, the reported error

! Package animate Error: Contents of first frame must not have zero width...

The animation should be saved in an ordinary lrbox and put as a \node on the second slide (\node<2> ...). The final animation frame should be repeated on the slides after the slide with the animation:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\usepackage{animate}

\newsavebox\myAnim

\begin{document}

  \begin{lrbox}{\myAnim}
    \begin{animateinline}[autoplay]{30}
    \multiframe{121}{iAngle=0+3}{
      \begin{tikzpicture}
        \useasboundingbox (3,0.5) rectangle (7,4.5);
        \draw [line width=1](5,2.5) arc (0:\iAngle:2);
      \end{tikzpicture}
    }
    \end{animateinline}
  \end{lrbox}

  \begin{frame}
     \begin{center}
        \begin{tikzpicture}
           \useasboundingbox (3,0.5) rectangle (7,4.5);
           \pause
           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           % animated object only on the second (<2>) slide
           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           \node<2> [inner sep=0, outer sep=0, anchor=south west] at (3,0.5) {\usebox\myAnim};
           \draw [name path=circle, line width=1](5,2.5) circle (2);
           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           \pause
           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           % repeat last animation frame on the slides to follow
           \begin{scope} %limit the clipping path on the `arc' object
             \clip (3,0.5) rectangle (7,4.5);
             \draw [line width=1](5,2.5) arc (0:360:2);
           \end{scope}
           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
           \draw [name path=line, line width=1](2,1)--(7,4) ;
           \path [name intersections={of = circle and line}];
           \coordinate (A) at (intersection-1);
           \coordinate (B) at (intersection-2);
           \pause
           \filldraw(A) circle (1.5pt);
           \pause    
           \filldraw(B) circle (1.5pt);
        \end{tikzpicture}
     \end{center}
  \end{frame}
\end{document}