3

I have come to look on how to draw a student law with Tex and I have been very pleased with the first answer I found here

Nevertheless, I found that the animation displayed in the first answer is even better than what I wanted to do.

But I am incapable of creating it. I have looked around for informations about the animate package, but my tries are unsuccessful.

I thought something like

%\documentclass[handout]{beamer}
\documentclass{beamer}
\usetheme[secheader]{Boadilla}
\usecolortheme{seahorse}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{hyperref}               % Pour les liens hypertexte
\usepackage{pgfplots}               % Pour les graphes
\usepackage{animate}                % Pour les animations
\def\basefunc{                      % La densité de Student
    gamma(.5*(\n+1))/(sqrt(\n*pi)*gamma(.5*\n))*((1+x^2/\n)^(-.5*(\n+1)))%
}

\begin{document}

\frame{
  \begin{animateinline}{1}
        \foreach \n in {1}{    
            \begin{tikzpicture}
            \begin{axis}[ymin=0,ymax=.41,   ]
                \addplot gnuplot [
                    smooth,
                    no marks,
                    domain={-6:+6},
                    ]{\basefunc};
                \legend{$n = \n$}
            \end{axis}
        \end{tikzpicture}
        }

    \foreach \n in {2, 3, 4, 5}{ 
    \newframe   
    \begin{tikzpicture}
            \begin{axis}[ymin=0,ymax=.41,   ]
                \addplot gnuplot [
                    smooth,
                    no marks,
                    domain={-6:+6},
                    ]{\basefunc};
                \legend{$n = \n$}
            \end{axis}
        \end{tikzpicture}
        }
  \end{animateline}
}

\end{document}

would work but it does not (I get a * \begin{lrbox} on input line 127 ended by \end{animateline}.* error).

Can someone help me ?

2
  • Am I right that you want a version of the linked answer that makes use of the animate package (instead of producing a document with many pages)?
    – AlexG
    Commented Jan 25, 2016 at 15:05
  • Yes you are, sorry if I was unclear. Commented Jan 25, 2016 at 15:07

1 Answer 1

5
  • definition of \basefunc modified to take one argument
  • \foreach... --> \multiframe...
  • use of siunitx package to format the number in the legend

pdflatex --shell-escape ...


\documentclass{beamer}

\usepackage{pgfplots}
\usepackage{animate}
\usepackage{siunitx}

\newcommand\basefunc[1]{%
    gamma(.5*(#1+1))/(sqrt(#1*pi)*gamma(.5*#1))*((1+x^2/#1)^(-.5*(#1+1)))%
}
\begin{document}

\begin{frame}{student}

\begin{animateinline}[controls, palindrome]{4} % four frames per second  
  \multiframe{20}{n=1+1}{ %20 frames with \n running from 1.0 trough 20.0
    \begin{tikzpicture}
        \begin{axis}[
            ymin=0,
            ymax=.41,
        ]
            \addplot gnuplot [
                smooth,
                no marks,
                domain={-6:+6},
              ]{\basefunc{\n}};
            \legend{$n = \num{\n}$}
        \end{axis}
    \end{tikzpicture}
  }  
\end{animateinline}

\end{frame}
\end{document}
2
  • That is perfect. If I may add a side question, how can I center that in my frame ? A centering do not seem to work, either before or after the \multiframe command Commented Jan 25, 2016 at 16:08
  • 1
    \begin{center}...\end{center} around the whole animateinline environment (as if you were centering something else).
    – AlexG
    Commented Jan 25, 2016 at 16:12

You must log in to answer this question.

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