Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing a long document and sometimes I need to recall a figure and show it (not just a \ref in the document). Right now every time I need this I rewrite the LaTeX code for showing the figure. Is there a way to recall a figure without rewriting it?

share|improve this question
add comment

3 Answers 3

enter image description here

Updated to avoid duplicating the caption and label information.

\documentclass{article}


\usepackage{graphics}


\makeatletter
\def\savefloat#1{%
\expandafter\def\expandafter\@endfloatbox\expandafter{%
\@endfloatbox
\global\setbox#1\copy\@currbox}}


 % Stephan Lehmke's \leaders trick to stop multiple writes.
\def\usefloat#1{%
\leavevmode\leaders\copy#1\hskip\wd#1\relax}

\makeatother

\newsavebox\myfloat

\begin{document}




aaaa

\begin{figure}

\fbox{\begin{tabular}{l}a\\b\\c\end{tabular}}
\caption{hmmm}
\end{figure}




aaaa

\begin{figure}

\fbox{\begin{tabular}{l}a\\b\\c\end{tabular}}
\caption{hoooo}\label{xx}
\savefloat\myfloat
\end{figure}



bbbb

it looked like this

\fbox{\scalebox{.25}{\usefloat\myfloat}}



\end{document}
share|improve this answer
2  
You gotta recognize David's answers even before you get to the badge at the very end... –  tohecz Dec 11 '12 at 15:49
add comment

You could define an entire float as the argument of a command such as \repeatedfigure. In the MWE below, this command takes an argument, which is the label to be assigned to the figure; if no extra label is desired, just specify an empty argument, {}. Oh, and I've assigned the h! location specifier to the repeated float as I'm assuming that you will wish to place it in very specific locations. If you're OK with LaTeX's default decision rules for placing floats, just remove the [h!] directive.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage[demo]{graphicx} % leave off demo option in real program
\usepackage{lipsum} % for filler text

\newcommand{\repeatedfigure}[1]{%
  \begin{figure}[h!] %
  \caption{Repeated caption} % replace with real caption text...
  \label{#1}
  \centering
  \includegraphics{demo.jpg} % use real filename if available
  \end{figure}}

\begin{document}
\lipsum[2]
\repeatedfigure{fig:repfig}
\lipsum[2]
\repeatedfigure{}
Here's a cross-reference to Figure~\ref{fig:repfig}.

\lipsum[2]
\repeatedfigure{}
\end{document}

Addendum: This setup assumes that you want each instance of the repeated figure to have its own caption and entry in the List of Figures. If that's not the case, you could define the \repeatedfigure macro as follows:

\newcommand{\repeatedfigure}[1]{%
  \begin{minipage}{\textwidth}
  \centering
  \includegraphics{demo.jpg}
  \end{minipage}}
share|improve this answer
    
I assume the figure will get a new number and a lof entry for every repeat... –  Stephan Lehmke Dec 11 '12 at 17:07
    
@StephanLehmke - Good point. I've provided an addendum to show what might be done if no repeated captions and entries in the LoF are needed. –  Mico Dec 11 '12 at 18:09
add comment

Just an alternatively solution to the other answers. I would create a "factory" macro to create commands for image and caption storage. Consider a graphic with the filename "amato":

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\def\imagefactory#1#2{%
\expandafter\def\csname#1\endcsname{%
  \includegraphics{#1}%
 }
 \expandafter\def\csname#1fig\endcsname{%
  \includegraphics{#1}%
  \captionof{figure}{#2}
 }
 \expandafter\def\csname#1float\endcsname{%
  \figure[htbp]
  \centering
  \includegraphics{#1}%
  \caption{#2}
  \endfigure
 }
}

\begin{document}
\imagefactory{amato}{This is a caption.}

\amato
\amatofig
\amatofloat

\end{document}

The MWE creates three commands a) just to store and provide a shorthand to includegraphics, the second essentially is a "here macro + caption" and the last a proper float. Stick the macros to a list and you have an image DB. Depending to what you need you can re-adjust the macros to do what you want (including references avoiding duplicating references - as per Dave's brilliant solution etc).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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