1

I am making an animation based on this answer. My problem is that as I animate, the value of time changes (e.g. from 0 ns to 100 ns), hence the size of the number changes, and the text ns moves back and forth. How can I fix the text's position, or get the coordinates (and maybe place it manually with this). Here is the code I am using:

\documentclass[t]{beamer}

\usepackage{animate}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepackage{siunitx}

\begin{filecontents*}{time-0.txt}
    0
\end{filecontents*}

\begin{filecontents*}{time-1.txt}
    100
\end{filecontents*}

\begin{document}

\begin{frame}{Electron Evolution}
    \pgfplotsset{compat=1.16}
    \centering
    \begin{animateinline}[loop,autoplay]{1}
%Schrodinger cat:https://tex.stackexchange.com/questions/544116/place-subfigures-in-l-shape/544119?noredirect=1#comment1375147_544119
        \multiframe{2}{i = 0 + 1}
        {
            \begin{tikzpicture}
            \begin{groupplot}[group style={group size=2 by 2,
                horizontal sep=1.2em,vertical sep=1.5em},
            xmin=0,height=4cm,width=5cm,no markers,
            ticklabel style = {font=\tiny},
            yticklabel pos=right,
            xlabel near ticks,
            xlabel style= {font=\tiny},
            ylabel near ticks,  
            ylabel style= {font=\tiny},     
            ]           
            \nextgroupplot[group/empty plot,alias=TL]
            \nextgroupplot[ylabel = {Particle Density~[m$^{-3}$]},
            xtick=\empty,
            ymin = 0,
            ymax = 77162484572430.92,
            xmin = 0.03157490368073539,
            xmax = 0.03653007600471181]
            %           
            \nextgroupplot[
            ytick=\empty,
            xlabel = {Probability Density},
            ymin = -217828.00503348646,
            ymax = 213540.67299828946,
            xmax = 1.1333435035653558e-05,
            xmin = 0,
            x dir = reverse,
            ]
            %
            \nextgroupplot[
            ylabel = {Speed~[m/s]},
            xlabel = {$z$~[m]},
            xmin = 0.03157490368073539,
            xmax = 0.03653007600471181,
            ymin = -217828.00503348646,
            ymax = 213540.67299828946,
            ]  
            \end{groupplot}
            \path (TL) node[align=left,font=\scriptsize]{$t=$ \input{time-\i.txt}~ns\\[0.6em]
                $r=\SI{0}{\meter}$\\[0.6em]
                $585$ macro-particles\\[0.6em]
                $\overline{T} = \SI{152.4}{\kelvin}$};  
            \end{tikzpicture}
        }
    \end{animateinline}
\end{frame}
\end{document}
Daniel Duque
  • 209
  • 1
  • 12

1 Answers1

1

To ensure a constant width of a specific content, wrap a \parbox around it

\parbox[<pos>]{<width>}{<text>}

See https://en.wikibooks.org/wiki/LaTeX/Boxes for more information on boxes and their options.

In this case a width of about 1.5em seems to be sufficient. If you want to fit exactly to the largest content, you could use \widthof or \settowidth as described in Get width of a given text as length.

To get the correct vertical alignment with respect to the rest of the line, use \parbox with [b] option.

In the end your code should read

\parbox[b]{1.5em}{\input{time-\i.txt}}
BambOo
  • 8,801
  • 2
  • 20
  • 47