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}
Character for character
The usage of the xstring
macros is taken from the linked question.
The width of the text (in \Huge
style) is saved to \mytextwidth
.
As \StrLen
counts from 0
to, in this case, 27
, \multiframe
needs to animate 28
frames, which is why \mylen+1
is calculated and saved to \frames
.
This example uses the \multiframe
macro because we can use variables (the other question used PGF
's \foreach
for this) and don't need to type every frame individually.
The \vphantom
is needed because we start with no text (\icounter=0
) and we need vertical height for. If you want to start with A
use icounter=1+1
and re-replace \frames
with \mylen
in the \multiframe
command.
\makebox
makes everytime a box of the full text's width so that animate
doesn't stretch the text. (We could have used also \StrRight
, but this needs less calculation.)
Code (char for char)
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{animate}
\usepackage{calc}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{animateinline}
\usepackage{xstring}
\def\mytext{Alles Gute zum Geburtstag!}
\StrLen{\mytext}[\mylen]
\newlength{\mytextwidth}
\setlength{\mytextwidth}{\widthof{\Huge\mytext}}
\def\frames{\number\numexpr\mylen+1\relax} % \frames = \mylen + 1
\begin{document}
\begin{center}
\begin{animateinline}[autoplay,loop]{2}
\multiframe{\frames}{icounter=0+1}{
\makebox[\mytextwidth][l]{\Huge\vphantom{\mytext}\StrLeft{\mytext}{\icounter}}
}
\end{animateinline}
\end{center}
\end{document}
Looks a lot like … (a.k.a. Output)
Word for word
Code
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{animate}
\usepackage{calc}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{animateinline}
\usepackage{xstring}
\def\mytext{Alles Gute zum Geburtstag!}
\StrCount{\mytext}{ }[\countSpaces]
\newlength{\mytextwidth}
\setlength{\mytextwidth}{\widthof{\Huge\mytext}}
\def\frames{\number\numexpr\countSpaces+2\relax} % \frames = \countSpaces + 2
\begin{document}
\begin{center}
\begin{animateinline}[autoplay,loop]{2}
\multiframe{\frames}{icounter=0+1,icounterr=1+1}{%
\makebox[\mytextwidth][l]{%
\Huge\vphantom{\mytext}%
\ifnum\icounter=0\relax\else
\ifnum\icounterr=\frames\relax\mytext\else%
\StrBefore[\icounter]{\mytext}{ }%
\fi
\fi
}%
}
\end{animateinline}
\end{center}
\end{document}
Best Answer
The easiest thing is to use the
animateinline
environment and then "manually" include the images, and lastly make the last image have a slow frame rate.However, I would like to show you a couple of possibilities with the
animate
package.Throughout this the distinction between image and frame is not enforced. Please ask if in doubt.
Animation problems
Often including an animation in a file creates huge pdf's which is often not desirable.
One way to circumvent this is to re-use the images whenever they have something in common. Thus for plots, some of the stuff in an animation that will be constant are:
All these are stored in each frame unless one carefully reuses them. As already hinted, this can greatly reduce the pdf file size (especially if a lot of the frames can be re-used, or combination thereof).
The feature known as timelines for the
animate
package can handle these things.The timeline has the capability of reusing several images without taking more space.
In the below examples I will demonstrate this.
animateinline
The
animateinline
environment is the manual way of including images, instead of using\animategraphics
. It also provides with some nice features to control the animation:\newframe
parses the current frame and goes to the next frame\newframe*
parses the current frame and goes to the next frame, however, an instantaneous pause is inserted in the frame.\newframe[<frame rate>]
parses the current frame and goes to the next frame, however, the frame rate for the remaining animation is set to<frame rate>
(notice that it is reset when it loops)Already here, you can infer your solution. Simply use the following:
If you did not include the last picture three times you would also experience a hang in between the 4th and 5th frame. Thus you need to include it three times. Try and experiment and see for yourself.
Timelines, the greatness of animations
This is probably where
animate
has a great advantage of use compared to out of the box animation creations. As already mentioned you are allowed to handle transparencies and combine however you wish each frame.The basic idea is a timeline file which holds information about when and how each frame is utilized.
Each line is made out of three columns, separated by a
:
. The three columns holds the following information:*
) or nothing (*
for pause)f
) or nothing (f
for frame rate),
) separated (the left-most format is the bottom one in the current frame)i
) tells animate to use framei
, frames start from count 0 (i
is the same asix1
)ixn
, wherei
andn
are integers (x
is actuallyx
).i
tells which frame to use andn
tells for how many frames it is going to stay on the animation. Thus:2x2
will tell the animation to insert frame 2 and stay for a total of 2 frames. Ifn=0
it will be there for the remaining part of the animation.c
which clears the transparency stack. This is useful for removing anyix0
frames inserted.For examples see
animate
.Example frames
Here is some code to generate several frames of interest.
This will create several files in the current folder.
Size decrease
Lets compare the images created in the previous section (on my pc that is):
fig<0-4>.pdf
are 18kb (all information)background.pdf
is 17kb (only axis descriptions and axis lines)fig_no_axis<0-4>.pdf
are 1.4kb (only data points)Ok, so already here you can infer what I mean about size reduction. It should be noted that these images does not contain many data points. Thus the size decrease is larger than would be expected for large data sets, however, if the number of frames are very large, it could have an impact on large data sets as well. Also creating animations from pdf's generally can utilize similar stuff (so the size change for pdf images are minimal).
Notice to have transparency on images
When using transparency on pictures (that is
0x0,1,2
) it is necessary that the images contain an alpha-channel, that is: transparency. I would recommend usingpng
images.Animation through timelines
Here are two codes which produces the same animation:
and using the constant background with the timeline:
Notice that we use the 0th frame for the entire animation, and also have the 1st image on the first frame (
0x0,1
).Inserting a pause as you requested for the last frame can be done like this:
Notice that now it is one more image long, with a changed frame rate for the last image. Through this, you can fine tune the frame rate, pauses etc. in the animation.
Notice that it could have been made shorter by having
background.pdf=fig_no_axes0.pdf
andfig_no_axes<0-4>.pdf=fig_no_axes<1-5>.pdf
and then used\animategraphics[timeline=<name>.tml]{5}{fig_no_axes}{0}{5}
.