3

I've created multiple .pdf files with animations using the animation package in R. For example, I have these two plots:

\documentclass{article}
\usepackage{animate}
\usepackage{graphicx}

\begin{document}

\begin{figure}
\begin{center}
\animategraphics[controls,width=.8\linewidth]{20}{Rplot8_7}{}{}
\end{center}
\end{figure}

\begin{figure}
\begin{center}
\animategraphics[controls,width=.8\linewidth]{20}{Rplot8_6}{}{}
\end{center}
\end{figure}

\end{document}

Here are the .pdf files:

Plot A

Plot B

I want to reduce the number of plots to one. So I would like to literally overlay one on top of the other and be able to navigate between these plots with a tab PLUS the ability to navigate between each plot's animations, which is what I have already. So I guess the idea is to have animation on two dimensions: one for the plots, and the other for each plot's animations. To make my point even more clear, here is a crudely drawn MS paint image:

Two dimensional animation

Of course, the final product would just look like one plot with two tabs to navigate between each animation. Is there a way to do this in LaTeX? I've looked at the animate package documentation and couldn't find much. If not, I will look for further options. Of course, any ideas to overcome this is appreciated. Thanks!

UPDATE: Some code I tried to do with more than 2 plots:

\documentclass{article}
\usepackage{animate}[2015/03/11]
\usepackage{graphicx}
\usepackage{ocgx}
\usepackage{fixocgx}

\begin{document}

\begin{figure}\centering
\makebox[0pt][l]{%
\begin{ocg}{A}{A}{1}%
  \animategraphics[controls,width=.8\linewidth]{20}{Rplot8_5}{}{}%
\end{ocg}%
}%
\begin{ocg}{B}{B}{0}%
  \animategraphics[controls,width=.8\linewidth]{20}{Rplot8_6}{}{}%
\end{ocg}
\begin{ocg}{C}{C}{0}%
  \animategraphics[controls,width=.8\linewidth]{20}{Rplot8_7}{}{}%
\end{ocg}

\actionsocg{A B C}{A}{B C}{\fbox{Plot A}}
\actionsocg{A B C}{B}{A C}{\fbox{Plot B}}
\actionsocg{A B C}{C}{A B}{\fbox{Plot C}}
\caption{Two animations on different layers}
\end{figure}

\end{document}

But I get something funky:

enter image description here

Is there a way to get the plots all in one spot instead of putting one on top of the other when space runs out?

  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Mar 29 '15 at 20:50
  • Take a look at section 8.1 in the documentation for the animate package. Find using texdoc.net with a search for animate. – R. Schumacher Mar 29 '15 at 21:34
  • @SoundsofSilence Thanks, I edited the post and sorry for not doing a MWE on my first post. I will keep it in mind for future posts! – Sanias Mar 30 '15 at 1:08
  • @R.Schumacher I am currently looking at the documentation and playing with the code to see if I can make it work. – Sanias Mar 30 '15 at 1:09
2

Animations can be put on PDF Layers using the ocgx and fixocgx packages. Package animate version 2015/03/11 is required.

\documentclass{article}
\usepackage{animate}[2015/03/11]
\usepackage{graphicx}
\usepackage{ocgx}
\usepackage{fixocgx}[2015/03/11]

\begin{document}

\begin{figure}\centering
\makebox[0pt][l]{%
\begin{ocg}{A}{A}{1}%
  \animategraphics[controls,width=.8\linewidth]{20}{Rplot8_5}{}{}%
\end{ocg}%
}%
\makebox[0pt][l]{%
\begin{ocg}{B}{B}{0}%
  \animategraphics[controls,width=.8\linewidth]{20}{Rplot8_6}{}{}%
\end{ocg}%
}%
\begin{ocg}{C}{C}{0}%
  \animategraphics[controls,width=.8\linewidth]{20}{Rplot8_7}{}{}%
\end{ocg}

\actionsocg{}{A}{B C}{\fbox{Plot A}}
\actionsocg{}{B}{A C}{\fbox{Plot B}}
\actionsocg{}{C}{A B}{\fbox{Plot C}}
\caption{Three animations on different layers}
\end{figure}

\end{document}

Every ocg environment, except the last one, must be placed into a zero-width \makebox. Also, line endings in between must be protected with '%' to prevent spurious space from being inserted. Then, all animated plots are placed on top of each other.

|improve this answer|||||
  • This works, but I am having trouble when I try to do this for more than two plots. The trouble is that the third plot is placed below the other two plots. I edited my first post for your convenience. Is there a way around this? And I apologize but I cannot put up a third .pdf file since my reputation is too low. :( – Sanias Mar 31 '15 at 4:19
  • You will have to put every ocg environment into a zero-width \makebox except the last one. And make sure that all line endings in between are protected with '%' to prevent spurious space from being inserted. – AlexG Mar 31 '15 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.