2

I am just starting to try animating tikz pictures in beamer. As a test, I want to have a ball move to the right. Here is the code. Any suggestions would be greatly appreciated.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}

\begin{document}

\begin{frame}
\begin{animateinline}[loop]{10}
  \multiframe{10}{rPos=0.1+0.5}{
    \begin{tikzpicture}
    [electron/.style={draw,fill,circle,shading=ball,text=white}]
    \node[electron] (e) at (\rPos,1) {$e^{-}$};
    \end{tikzpicture}
  }
\end{animateinline}
\end{frame}

\end{document}
2

You need to set a common bounding box for all animation frames which encompasses all positions of the electron. Otherwise the animation's viewport moves with the electron.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}

\begin{document}

\begin{frame}
  \begin{animateinline}[loop]{10}
  \multiframe{10}{rPos=0.1+0.5}{
    \begin{tikzpicture}
    [electron/.style={draw,fill,circle,shading=ball,text=white}]
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \useasboundingbox (-0.4,0.5) rectangle (5.1,1.5);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \node[electron] (e) at (\rPos,1) {$e^{-}$};
    \end{tikzpicture}
  }
  \end{animateinline}
\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.