1

I'm learning the basics of the animate package. In a simple image I want to insert a counter that represents the time. Here there is the code I've used.

 \documentclass[12pt]{article}
   \usepackage[italian]{babel}
   \usepackage{tikz}
   \usepackage[controls]{animate} 
    %=====================
    \begin{document}
    %=====================

   \begin{figure}

\begin{animateinline}
   [
        loop,
        controls,
        begin={
                      \begin{tikzpicture}
                      \useasboundingbox (-3,-3) rectangle (10, 5);
                   },
       end={\end{tikzpicture}}
   ]{10}
 \multiframe {40}{n=0+0.05}  % andata
{ 
\draw[very thick](-2,0) -- (-1,0); %linee
\draw[very thick](-2,2) -- (-1,2);
%
\draw[->,very thick](0,0) -- (9,0); %assi
  \draw[->,very thick](0,-2) -- (0,4);
  \filldraw [red] (-1.5,0+\n) circle (1pt) ;                %fotone
\draw[dashed,red] (-1.5,0+\n)--(0+\n,0+\n); %proiezione
 \draw [thick,red] (0,0)--(0+\n,0+\n); %grafico
%%counter
 \node [thick, black] at (1,-1){$t=$};
 \node [thick, black] at (2,-1){$\n$};
}
%
 \multiframe {40}{n=0+0.05}     %ritorno
{ 
\draw[very thick](-2,0) -- (-1,0); %linee
\draw[very thick](-2,2) -- (-1,2);
%
\draw[->,very thick](0,0) -- (9,0); %assi
  \draw[->,very thick](0,-2) -- (0,4);
  \draw [red] (0,0)--(2,2);
   \filldraw [blue] (-1.5,2-\n) circle (1pt) ;                  %fotone
\draw[dashed,blue] (-1.5,2-\n)--(2+\n,2-\n); %proiezione
 \draw [thick,blue] (2,2)--(2+\n,2-\n); % grafico
}

\end{animateinline}
%
\end{figure}
%======================
\end{document}
%======================

With this solution the digits of the number that represents the time change all at any frame, giving a fastidious effect of blink that it is also difficult to read. So my question is: there is some way to have a counter that change only the changing digit, as in a digital timer?

2
  • Please edit your post and add a working document, not just the fragments
    – user31729
    Dec 8, 2015 at 17:09
  • I've added all the code. But it seems not possible to add the pdf image that is generated. Dec 8, 2015 at 17:41

1 Answer 1

1

This question is more about formatting numbers. The siunitx package is perfectly suited for this purpose as it allows rounding numbers to significant decimal places and correctly typesetting physical units.

E. g. a number with unit:

$t=\SI[round-mode=places,round-precision=2]{123.4567}{\second}$

should appear as "t = 123.46 s" on paper.

Or without unit:

$t=\num[round-mode=places,round-precision=2]{123.4567}$

One animate-related recommendation concerning the given code is to always separate two subsequent \multiframe blocks with a \newframe (as stated somewhere in the animate documentation).


\documentclass[12pt]{article}
%\usepackage[italian]{babel}
\usepackage{tikz}
\usepackage[controls]{animate} 
\usepackage{siunitx}

%=====================
\begin{document}
%=====================

\begin{figure}

\begin{animateinline}
[
  loop,
  begin={
    \begin{tikzpicture}
    \useasboundingbox (-3,-3) rectangle (10, 5);
  },
  end={\end{tikzpicture}}
]{10}
  \multiframe {40}{n=0+0.05}  % andata
  { 
    \draw[very thick](-2,0) -- (-1,0); %linee
    \draw[very thick](-2,2) -- (-1,2);
    %
    \draw[->,very thick](0,0) -- (9,0); %assi
      \draw[->,very thick](0,-2) -- (0,4);
      \filldraw [red] (-1.5,0+\n) circle (1pt) ;                %fotone
    \draw[dashed,red] (-1.5,0+\n)--(0+\n,0+\n); %proiezione
     \draw [thick,red] (0,0)--(0+\n,0+\n); %grafico
    %counter
    \node [thick, black] at (1,-1){$t=\SI[round-mode=places,round-precision=2]{\n}{\second}$};
  }
  \newframe% required between two \multiframe blocks
  \multiframe {40}{n=0+0.05, nTime=2+0.05}     %ritorno
  { 
    \draw[very thick](-2,0) -- (-1,0); %linee
    \draw[very thick](-2,2) -- (-1,2);
    %
    \draw[->,very thick](0,0) -- (9,0); %assi
    \draw[->,very thick](0,-2) -- (0,4);
    \draw [red] (0,0)--(2,2);
    \filldraw [blue] (-1.5,2-\n) circle (1pt) ;                  %fotone
    \draw[dashed,blue] (-1.5,2-\n)--(2+\n,2-\n); %proiezione
    \draw [thick,blue] (2,2)--(2+\n,2-\n); % grafico
    %counter
    \node [thick, black] at (1,-1){$t=\SI[round-mode=places,round-precision=2]{\nTime}{\second}$};
  }

\end{animateinline}
%
\caption{\dots}
\end{figure}
%======================
\end{document}
%======================
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .