Graphics, Figures & TablesCaption at PSTricks animation

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Caption at PSTricks animation

Post by svend_tveskaeg »

Hi all.

Consider the following example:

Code: Select all

% Compile using
%
% latex <filename>.tex
% dvips -Ppdf -D1200 <filename>.dvi
% ps2pdf <filename>.ps
%
% and open with Adobe Reader.

\documentclass{article}

\usepackage[figureposition=bottom]{caption}
\usepackage{pst-func}
\usepackage{animate}

% Easier when there are a lot of floating figures.
\makeatletter
  \providecommand*{\setfloatlocations}[2]{\@namedef{fps@#1}{#2}}
\makeatother
\setfloatlocations{figure}{htbp}

\newcommand*{\studentT}[1]{
\psset{xunit=0.9cm,yunit=9cm}
 \begin{pspicture}(-6,-0.1)(6,0.5)
  \psaxes[Dy=0.1]{->}(0,0)(-5,0)(5.5,0.45)[$x$,0][$y$,90]
  \pscustom[fillstyle=solid,fillcolor=blue!40,opacity=0.4,linecolor=red,linestyle=none]{%
    \psline(0,0)(-5,0)
    \psTDist[nue = #1]{-5}{5}
    \psline(5,0)(0,0)
  }
  \psTDist[nue=#1,linecolor=red,linewidth=1pt]{-5}{5}
  \rput(3,0.3){$\nu = #1$}
 \end{pspicture}
% \caption{Student's $t$-distribution.}
}

\begin{document}

\begin{figure}
\centering
 \begin{animateinline}[poster=first,controls,palindrome]{10}
  \multiframe{50}{rA=0.02+0.02}{\studentT{\rA}}
 \end{animateinline}
\end{figure}

\end{document}
Is it possible to create a \caption under the animation? If I do not outcomment the \caption line in the example, the code will not compile?

Thank you in advance!

P.S. I cannot find anything regarding my issue in the documentation for the animate package or the caption package.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Caption at PSTricks animation

Post by svend_tveskaeg »

I just had to place the caption correct. :D The following works:

Code: Select all

% Compile using
%
% latex <filename>.tex
% dvips -Ppdf -D1200 <filename>.dvi
% ps2pdf <filename>.ps
%
% and open with Adobe Reader.

\documentclass{article}

\usepackage[figureposition=bottom]{caption}
\usepackage{pst-func}
\usepackage{animate}

% Easier when there are a lot of floating figures.
\makeatletter
  \providecommand*{\setfloatlocations}[2]{\@namedef{fps@#1}{#2}}
\makeatother
\setfloatlocations{figure}{htbp}

\newcommand*{\studentT}[1]{
\psset{xunit=0.9cm,yunit=9cm}
 \begin{pspicture}(-6,-0.1)(6,0.5)
  \psaxes[Dy=0.1]{->}(0,0)(-5,0)(5.5,0.45)[$x$,0][$y$,90]
  \pscustom[fillstyle=solid,fillcolor=blue!40,opacity=0.4,linecolor=red,linestyle=none]{%
    \psline(0,0)(-5,0)
    \psTDist[nue = #1]{-5}{5}
    \psline(5,0)(0,0)
  }
  \psTDist[nue=#1,linecolor=red,linewidth=1pt]{-5}{5}
  \rput(3,0.3){$\nu = #1$}
 \end{pspicture}
}

\begin{document}

\begin{figure}
\centering
 \begin{animateinline}[poster=first,controls,palindrome]{10}
  \multiframe{50}{rA=0.02+0.02}{\studentT{\rA}}
 \end{animateinline}
\caption{Student's $t$-distribution.}
\end{figure}

\end{document}
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Caption at PSTricks animation

Post by CrazyHorse »

svend_tveskaeg wrote: Is it possible to create a \caption under the animation? If I do not outcomment the \caption line in the example, the code will not compile?

P.S. I cannot find anything regarding my issue in the documentation for the animate package or the caption package.
you cannot put the caption inside the loop, then the figurenumber will also be increased every time. Put it under buttons:

Code: Select all

\documentclass{article}

\usepackage{caption}
\usepackage{pst-func}
\usepackage{animate}

\psset{xunit=0.9cm,yunit=9cm}
\newcommand*\studentT[1]{%
 \begin{pspicture}(-6,-0.1)(6,0.5)
  \psaxes[Dy=0.1]{->}(0,0)(-5,0)(5.5,0.45)[$x$,0][$y$,90]
  \pscustom[fillstyle=solid,fillcolor=blue!40,opacity=0.4,linecolor=red,linestyle=none]{%
    \psline(0,0)(-5,0)
    \psTDist[nue=#1]{-5}{5}
    \psline(5,0)(0,0)
  }
  \psTDist[nue=#1,linecolor=red,linewidth=1pt]{-5}{5}
  \rput(3,0.3){$\nu = #1$}
 \end{pspicture}}

\begin{document}

\begin{center}
 \begin{animateinline}[poster=first,controls,palindrome]{10}
  \multiframe{50}{rA=0.02+0.02}{\studentT{\rA}}
 \end{animateinline}
 \captionof{figure}{Student's $t$-distribution.}
\end{center}

\end{document}
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Caption at PSTricks animation

Post by svend_tveskaeg »

CrazyHorse wrote:Put it under buttons
Exactly. I did just that in my second post. ;)

Have you, otherwise, changed the code?

P.S. Here is my final code -- unless someone teels my how to improve it -- for the animation (but I have a lot of other stuff in the (Danish) document so the code you see here is overkill):

Code: Select all

% Compile using
%
% latex <filename>.tex
% dvips -Ppdf -D1200 <filename>.dvi
% ps2pdf <filename>.ps
%
% and open with Adobe Reader.

\documentclass[
  a4paper,
  10pt,
  danish
]{article}

\usepackage{babel}
\usepackage[
  utf8
]{inputenc}
\usepackage[
  hmargin=3cm,
  vmargin=2.4cm
]{geometry}
\usepackage[
  figureposition=bottom
]{caption}
\usepackage{pst-func}
\usepackage{animate}
\usepackage[
  locale=DE
]{siunitx}
\usepackage{microtype}
\usepackage{hyperref}

\DisableLigatures[f]{encoding=T1}

\setcounter{secnumdepth}{0}

\makeatletter
  \providecommand*{\setfloatlocations}[2]{\@namedef{fps@#1}{#2}}
\makeatother
\setfloatlocations{figure}{htbp}

\addto\extrasdanish{%
  \def\figureautorefname{\textsc{Figur}}
}

\DeclareCaptionLabelSeparator{tilpasning}{:\quad}
\captionsetup{
  font=small,
  labelfont=sc,
  labelsep=tilpasning,
  width=0.6\textwidth
}

\newcommand*{\studentT}[1]{
\psset{xunit=1cm,yunit=10cm}
 \begin{pspicture}(-6,-0.1)(6,0.5)
  \psaxes[Dy=0.1,comma]{->}(0,0)(-5.3,0)(5.5,0.45)[$x$,0][$y$,90]
  \pscustom[fillstyle=solid,fillcolor=blue!40,opacity=0.4,linecolor=red,linestyle=none]{%
    \psline(0,0)(-5,0)
    \psTDist[nue = #1]{-5}{5}
    \psline(5,0)(0,0)
  }
  \psTDist[nue=#1,linecolor=red,linewidth=1pt]{-5}{5}
  \rput(3,0.3){$\nu = \num[round-mode=places,round-precision=1]{#1}$}
 \end{pspicture}
}

\begin{document}

\begin{center}
  \Huge{\textbf{Sandsynlighedsfordelinger}}
\end{center}
\vspace{10ex}

\noindent \textbf{Vigtigt:} \enskip Dokumentet skal åbnes med \textsf{Adobe Reader}, da dette program (så vidt jeg ved) er den eneste PDF-fremviser, der kan håndtere PostScript-animationer korrekt.

\section{Den studerenes \texorpdfstring{$t$}{t}-fordeling}
\begin{figure}
\centering
 \begin{animateinline}[poster=first,controls,palindrome]{10}
  \multiframe{51}{rA=0.0001+0.1}{\studentT{\rA}}
 \end{animateinline}
\caption{Den studerenes $t$-fordeling.}
\end{figure}

\end{document}
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Caption at PSTricks animation

Post by CrazyHorse »

svend_tveskaeg wrote:
CrazyHorse wrote:Put it under buttons
Exactly. I did just that in my second post. ;)

Have you, otherwise, changed the code?
no, I was "blinded by the light"; didn't saw the second post ...
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Caption at PSTricks animation

Post by svend_tveskaeg »

Okay. Thank you.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply