Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm used to prepare tikz graphics with preview or standalone packages to crop them. Now I've started to experiment with animations and wanted to do the same. My first test was with Alexander Grahn's answer to Animating Protocols, but as soon as I include

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

in its preamble, pdflatex complains with

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

I've found some examples prepared with preview but all of them use \animategraphics command instead of animateinline environment with \multiframe command.

So my first question is, has any sense to do what I want? It is producing an animated clipped graphic to be included in another file. "No, it hasn't" can be a good answer but if it has, what am I doing wrong?

Here you have the code to test it. I've also tested adding a \usebaoundingbox but without any succes.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{frame}
\begin{animateinline}[loop]{10}
  \multiframe{10}{rPos=0.1+0.1}{
    \begin{tikzpicture}[every node/.style={draw}]
     %\useasboundingbox (-2,-2) rectangle (7,2);
     \node (s) {sender};
     \node (r) at (5,0) {receiver};
     \path (s) -- (r) node[pos=\rPos,coordinate] (p) {};
     \draw[->] (s) -- (p);
    \end{tikzpicture}
  }
\end{animateinline}
\end{frame}

\end{document}
share|improve this question
    
Did you tried it with a normal document class? IIRC beamer doesn't work nicely with preview as well. –  Martin Scharrer Aug 5 '11 at 9:59
    
@Ignasi: As Martin said in his answer and his comment to KF Leong, there isn't much point in using preview with animate other than getting a tightly cropped PDF around the animation. You cannot \includegraphics or \includepdf it into another document, because the PDF annotations, which provide interactivity, get lost in this process. They have to be re-built in every new PDF document. Therefore standalone is probably the better choice. –  AlexG Aug 5 '11 at 12:00
    
@Alexander: I tested preview with animate because I use it with tikz graphics but now I'll try with standalone. By the way, including a newframe (with a tikzpicture) before the multiframe it's also a possible workarround. –  Ignasi Aug 8 '11 at 9:39
add comment

2 Answers

up vote 3 down vote accepted

Here a solution which uses the standalone class. As said, animations will be lost if you include that PDF as image in another document. However, you could just \input the file below after loading the standalone package in the main document.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
\begin{animateinline}[loop]{10}
  \multiframe{10}{rPos=0.1+0.1}{
    \begin{tikzpicture}[every node/.style={draw}]
     %\useasboundingbox (-2,-2) rectangle (7,2);
     \node (s) {sender};
     \node (r) at (5,0) {receiver};
     \path (s) -- (r) node[pos=\rPos,coordinate] (p) {};
     \draw[->] (s) -- (p);
    \end{tikzpicture}
  }
\end{animateinline}
\end{document}
share|improve this answer
1  
Thanks, @Martin, for the pointer to the standalone class and package (+1). It allows for combining self-contained documents into a main one without (re)moving the preambles, right? –  AlexG Aug 5 '11 at 11:47
    
@Alex: Yes, exactly. It can also copy the sub-preambles to the main one if the subpreambles option is used with the package. This requires one additional compiler run. –  Martin Scharrer Aug 5 '11 at 12:24
    
Neither xelatex nor latex-dvips-ps2pdf can compile it. ps2pdf produced error message: Error: /undefined in pgfo Operand stack: Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1910 1 3 %oparray_pop 1909 1 3 %oparray_pop 1893 to be continued... –  xport Aug 6 '11 at 3:49
    
This code also does not work with PSTricks and animate. –  xport Aug 7 '11 at 12:06
    
@xport: Try the new v1.0 of standalone which is much better for XeLaTeX. –  Martin Scharrer Dec 21 '11 at 16:22
show 5 more comments

Change the \PreviewEnvironment option to animateinline.

share|improve this answer
1  
Indeed, changing \PreviewEnvironment{tikzpicture} to \PreviewEnvironment{animateinline} does it. It also works with a different class as beamer, but you will get other fonts by default. Note that the animation will be lost if you include that PDF as image in another document. –  Martin Scharrer Aug 5 '11 at 11:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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