5

I am currently working on a conference presentation and I am using the very nice tikz and pgfplotspackages in combination with beamer.

To stress out some content in my figures, I use beamer's overlay system.

When I use some small tikzpictures everything is integrated inside the document using some \input commands. However, for large pgfplots figures (you see me coming), I have quite long compilation times.

My current solution is to precompile my big pictures separately using multiple tikzpictures and to call some \includegraphics with overlay options.

Beamer code

\documentclass{beamer}
\begin{document}
\begin{frame}
\includegraphics<1>[page=1]{image}
\includegraphics<2>[page=2]{image}
\includegraphics<3->[page=3]{image}
\end{frame}
\end{document}

where image is built using

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[]
    % Plot to be displayed on overlay 1
        \addplot[domain=0:1,samples=100]{x}; 
    \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
    \begin{axis}[]
        % Plots to be displayed on overlay 2
        \addplot[domain=0:1,samples=100]{x}; 
        \addplot[domain=0:1,samples=100]{x^2}; 
    \end{axis}
\end{tikzpicture}
% And so on
\end{document}

I know there are some externalization ways to do this, but I was wondering what the opinion of the community was on this matter.

Sorry in advance, if this is a double.

EDIT related to standalone beamer option

Using standalone with the beamer option seems to produce an nteresting result (thanks samcarter). However, the output has the size of a beamer frame, instead of fitting the pgfplots axis. See the MWE below.

\documentclass[beamer]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{standaloneframe}
\begin{tikzpicture}
\begin{axis}[]
\only<1>{\addplot[domain=0:1, samples=100]{x};}
\addplot[domain=0:1, samples=100]{x^2};
\addplot[domain=0:1, samples=100]{x^3};
\only<4>{\addplot[domain=0:1, samples=100]{x^4}};
\end{axis}
\end{tikzpicture}
\end{standaloneframe}
\end{document}
  • 1
    Maybe it would be easier to answer if you include some example. – user36296 Jun 8 '18 at 9:49
  • You could also use the standalone class to pre-compile the figures including overlays - the class has a special beamer option to allow for overlays and such. – user36296 Jun 8 '18 at 9:51
  • Yes, it does. This option will allow overlays. As a side effect, it will also set the papersize to the one from beamer and not crop the images, but this can easily be undone. – user36296 Jun 8 '18 at 10:26
  • Sorry, I just saw your comment. It is working nicely, except for the paper size. Do you have any ideas to redefine the paper size to fit the actual pictures ? – BambOo Jun 8 '18 at 10:39
  • 1
    Just found an old answer: tex.stackexchange.com/questions/426910/… – user36296 Jun 8 '18 at 10:42
2

Pass the tikz and preview options to standalone:

\documentclass[beamer,tikz,preview]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{standaloneframe}
\begin{tikzpicture}
  \begin{axis}[]
  \only<1>{\addplot[domain=0:1, samples=100]{x};}
  \addplot[domain=0:1, samples=100]{x^2};
  \addplot[domain=0:1, samples=100]{x^3};
  \only<4>{\addplot[domain=0:1, samples=100]{x^4}};
  \end{axis}
\end{tikzpicture}
\end{standaloneframe}
\end{document}

Compiling this with pdflatex results in a nicely cropped, 4 page PDF. For easy embedding into the beamer frames, I recommend the following pattern:

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}
  \foreach \ov/\pg in {1/1,2/2,3-/3}{ 
    \includegraphics<\ov>[page=\pg]{image.pdf}
  } 
  \onslide<4>{Still the last figure!}
\end{frame}
\end{document}

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.