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 trying to have an animated tikz graph with floating point values. While I can use floating point values as parameters for the graph, I can't seem to find a way to do so for displayed equations. Below is a MWE using beamer. The green line is animated properly - but the parameter does not appear in simplified form. The blue line shows the parameter appearing the way I would like it to (as a simplified number) but it is not updated in the tikz picture, even though it is updated outside that picture.

\documentclass[12pt]{beamer}

\usepackage{animate}
\usepackage{fp}
\usepackage{tikz}

\begin{document}

\newcounter{step}   
\setcounter{step}{1}

\newcommand{\scalevalues}{ %
\FPmul{\scaled}{\thestep}{0.1}
\FPtrunc{\scaled}{\scaled}{1}
}

\scalevalues   
\scaled % will print 0.1 above picture

\begin{animateinline}[loop, poster = first, controls, palindrome]{10}
\whiledo{\thestep < 21}{
    \begin{tikzpicture}
    %\useasboundingbox (-1,-1) rectangle (5,5);
    %
    \draw[->] (-1,0) -- (5,0) node[anchor=west]{\color{gray}x};
    \draw[->] (0,-1) -- (0,5) node[anchor=south]{\color{gray}y};
    % 
    \draw[-, thick, blue] (\scaled,-1) -- (5,4) node[anchor=east]{$\scaled x $};
    \draw[-, thick, green] (0.1*\thestep,-1) -- (2,3) node[anchor=east]{$0.1*\thestep x $};
    \end{tikzpicture}
    \stepcounter{step}
    \scalevalues  
    \scaled % will print updated values below picture
    \ifthenelse{\thestep < 21}{
            \newframe
    }{
        \end{animateinline}\relax 
    }
}

\end{document}
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You have to carry out the calculation somehow but TikZ don't quite get that it's a computation it has to perform. So you can make it obvious by

{$\pgfmathparse{0.1*\thestep}\pgfmathprintnumber[fixed,precision=1]\pgfmathresult x $}

in that node.

share|improve this answer
    
Wow, that was fast! Thanks... I have to wait a few minutes until I can accept it. –  André Oct 6 '12 at 21:11
    
@André No rush. Maybe someone else comes along with a better answer :) –  percusse Oct 6 '12 at 21:11
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.