What is the best way to combine tikz pictures and beamer overlays

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
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[]
% Plots to be displayed on overlay 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}[]
\end{axis}
\end{tikzpicture}
\end{standaloneframe}
\end{document}

• Maybe it would be easier to answer if you include some example. – samcarter_is_at_topanswers.xyz 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. – samcarter_is_at_topanswers.xyz 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. – samcarter_is_at_topanswers.xyz 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
• Just found an old answer: tex.stackexchange.com/questions/426910/… – samcarter_is_at_topanswers.xyz Jun 8 '18 at 10:42

Pass the tikz and preview options to standalone:

\documentclass[beamer,tikz,preview]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{standaloneframe}
\begin{tikzpicture}
\begin{axis}[]
\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}