What I would like to achieve is, in a later frame, I would want a specific figure to reappear so that I can talk more about it, preferably keeping the original figure counter number. In both occurrences, there would be some text or other stuff accompanying the figure.
This question is similar to this, this, or this.
The solution in the first link seems to be too manual, the second seems nice but I couldn't get it to compile in a beamer document, and the third only touches the issue about figure counter. I tried to use a lrbox
environment to save the contents of the figure, but this also does not seem to work:
\documentclass{beamer}
\usepackage{tikz}
\setbeamertemplate{caption}{{\small\bfseries\MakeUppercase{\insertcaptionname~\insertcaptionnumber}}\quad\insertcaption}
\newsavebox{\myfigurebox}
\begin{document}
\begin{frame}{First Frame}
\begin{lrbox}{\myfigurebox}
\begin{tikzpicture}
\draw (0,0) -- ++(75:1 cm) -- ++(-75:1 cm);
\end{tikzpicture}
\end{lrbox}
\begin{figure}
\centering
\usebox{\myfigurebox}
\caption{Description.}
\end{figure}
Some text.
\end{frame}
\begin{frame}{Other Frame}
\begin{figure}
\centering
\usebox{\myfigurebox}
\caption{Description (again).}
\end{figure}
More text.
\end{frame}
\end{document}
Other variations are also tried, e.g. surrounding the figure
environment with lrbox
, moving lrbox
outside a frame
etc, but these didn't work either.
Right now, the only close solution I had is to use overlay specifications and an \againframe
, but this messes up the equation numbers or other counters.
\documentclass{beamer}
\usepackage{tikz}
\setbeamertemplate{caption}{{\small\bfseries\MakeUppercase{\insertcaptionname~\insertcaptionnumber}}\quad\insertcaption}
\begin{document}
\begin{frame}<1>[label=myframe]
\frametitle<1>{First Frame}
\frametitle<2>{Other Frame}
\begin{figure}
\centering
\begin{tikzpicture}
\draw (0,0) -- ++(75:1 cm) -- ++(-75:1 cm);
\end{tikzpicture}
\caption{Description.}
\end{figure}
\begin{overprint}
\onslide<1>
Some text.
\onslide<2>
More text. % imagine there are some equations or other counters here; the equation numbering would be wrong
\end{overprint}
\end{frame}
% later...
\againframe<2>{myframe}
\end{document}
And this way of "hacking" might get out of control if the same figure is repeated a lot of different times…
Best Answer
Having the
\begin{lrbox}
etc within aframe
makes it local to theframe
, hence it cannot be recalled later, unless defining agloballrbox
environment and using that instead. Such a definition might be done byThe figure numbers will be different because the
\caption
command is responsible for assigning the numbers, and you have two\caption
commands. Probably trying to put the wholefigure
environment within a box is not going to be easy (and you can't put thecaption
in the box without thefigure
environment either), and does not allow you to append the text "(again)" to the caption the second time, so better to fiddle with the labels/counters, as I have done below, extending the example to show the effect on having other figures in between.In the following I have avoided using the
globallrbox
environment and moved thelrbox
outside of the frame to better illustrate the various approaches. You could probably tidy this up further by providing additional macros/environments for saving and recalling figures.Update: slightly better interface?
With this version, use a
savefigure
environment anywhere before you want the first copy of that figure to appear, providing a label in the first argument by which to recall it later. The figure is then called up or recalled with either the\figurefirstuse
or\reusefigure
command, depending whether it has been shown already or not. The arguments to these commands are the label name and the caption, which need not be the same for all recalls of the same image. It does not currently save any previously used caption(s) automatically.Not sure if all this stuff is necessary or elegant, but seems to work, now also when there are overlays. Note that there are some limitations with regards to error handling at the very least. It is not easy to automatically determine if the figure is being used for the first time or not because
beamer
resets thefigure
counter when it reprocesses the frame for multiple slides (ie overlays and pauses), hence I have given up on trying to do that for now.There is also a
figureandsave
environment which saves the figure and shows it in the same place, internally calling the above commands. Takes the same arguments as for\figurefirstuse
in this case.I have left the previous version above as it may be clearer what's actually going on. The following example should hopefully illustrate the new interface better than my description of it.