9

I have drawn a schematic geometry an I want to describe the results of simulations I did with several configuration. So in Section XY I describe the simulations I did with a case set-up using the parameter set A refering to Figure 23 that contains the sketch of the geometry.

Later in Section XZ I write about simulations on a case using parameter set B. In order to avoid referring to a Figure that is located 10 pages earlier in the document I want to repeat Figure 23.

So I have several questions:

  • Should I use the same figure number? If I repeat equations I use \tag{\ref{}} to get the same equation number. How can I achieve this with Figures?
  • Can I reuse the figure caption somehow by some latex magic in order to avoid code duplication?
  • Is there a correct way to do this? Am I violating some rules of style for thesis writing with my intended solution? I am aware that having the Figure 23 at page 67 and at page 89 feels weird, but as it is the same Figure, it seems to me to be the honest solution.

I am aware of the questions

5
  • Are you using hyperref? What about a \listoffigures? How is that supposed to handle your re-use of the figure?
    – Werner
    Commented Jan 26, 2015 at 21:39
  • 2
    I wouldn't do that if I were you, stranger. :) It could be honest, but often members of the tribunal do not have an open mind to imaginative formats. The comment could be "you mistakenly put the same image twice". Any document should be clear, concise, complete and brief. Could be your thesis more clear, concise, complete or brief with a duplicated image? Doubtful.
    – Fran
    Commented Jan 26, 2015 at 22:18
  • Can't you reference the same figure 23 with \vref{fig:23}at page 87 with varioref without putting the image twice as @Fran said. Also see Cross-reference packages: which to use, which conflict? Commented Jan 27, 2015 at 4:21
  • @Fran So, I should not enforce the same figure number. I want to show the figure again, for the reader to be able to link the parameters listed in a table to the geometric dimensions of the sketch of the geometry.
    – Dohn Joe
    Commented Jan 27, 2015 at 9:53
  • 1
    @DohnJoe If you consider imperative show the figure again, my suggestion is mix / join /include the image in the table (or viceversa) in a new figure, table or another type of float, with a reference in the caption to the first figure, so it should be evident that you ask to the reader to look at the same image again for another reason. Moreover, this simplify your life at the time of make cross-references and lists of figures and tables, without without the need to show duplicate entries.
    – Fran
    Commented Jan 27, 2015 at 12:31

2 Answers 2

6

I would duplicate the figure contents, just using a new environment that does some setup which avoids problems:

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}

% \begin{reusefigure}[<float spec>]{<ref>}
\newenvironment{reusefigure}[2][htbp]
  {\addtocounter{figure}{-1}%
   \renewcommand{\theHfigure}{dupe-fig}% If you're using hyperref
   \renewcommand{\thefigure}{\ref{#2}}% Figure counter is \ref
   %\renewcommand{\thefigure}{\ref{#2} (repeated)}% Figure counter + "(repeated)"
   \renewcommand{\addcontentsline}[3]{}% Avoid placing figure in LoF
   \begin{figure}[#1]}
  {\end{figure}}

\begin{document}

We have Figures~\ref{fig:caption-a},~\ref{fig:caption-b} and~\ref{fig:caption-c}.

\begin{figure}[ht]
  \centering\includegraphics[height=50pt]{example-image-a}
  \caption{A figure caption}\label{fig:caption-a}
\end{figure}

\begin{reusefigure}[ht]{fig:caption-a}
  \centering\includegraphics[height=50pt]{example-image-b}
  \caption{A figure caption}\label{fig:caption-b}
\end{reusefigure}

\begin{figure}[ht]
  \centering\includegraphics[height=50pt]{example-image-c}
  \caption{Another figure}\label{fig:caption-c}
\end{figure}

\end{document}

The reusefigure environment takes two arguments. The first is optional and similar to the float specification of regular figure floats. The second is mandatory and takes the \label of the figure to be reused.

Appropriate settings are adjusted prior to re-using the figure, including settings that for use with hyperref. Entry into the LoF is avoided, since it's not necessary.


Here is an implementation that automates the process. A to-be-used-later figure is constructed using sourcefigure. Then, to reuse this figure, use \reusefigure[<float spec>]{<ref>} where you specify the <ref> used in the \label of sourcefigure:

\documentclass{article}
\usepackage{graphicx,environ}
\usepackage{hyperref}

\NewEnviron{sourcefigure}[1][htbp]{%
  {\let\caption\relax\let\ref\relax
   \renewcommand{\label}[1]{%
    \gdef\sfname{sf:##1}}%
    \setbox1=\hbox{\BODY}}% Capture \label
    \global\expandafter\let\csname\sfname\endcsname\BODY% Capture entire figure
  \begin{figure}[#1]
    \BODY
  \end{figure}
}
\newcommand{\reusefigure}[2][htbp]{%
  {\addtocounter{figure}{-1}%
   \renewcommand{\theHfigure}{dupe-fig}% If you're using hyperref
   \renewcommand{\thefigure}{\ref{#2}}% Figure counter is \ref
   %\renewcommand{\thefigure}{\ref{#2} (repeated)}% Figure counter + "(repeated)"
   \renewcommand{\addcontentsline}[3]{}% Avoid placing figure in LoF
   \renewcommand{\label}[1]{}% Make \label inactive
   \begin{figure}[#1] \csname sf:#2\endcsname \end{figure}}
}

\begin{document}

We have Figures~\ref{fig:caption-a} and~\ref{fig:caption-c}.

\begin{sourcefigure}[ht]
  \centering\includegraphics[height=50pt]{example-image-a}
  \caption{A figure caption}\label{fig:caption-a}
\end{sourcefigure}

\reusefigure[ht]{fig:caption-a}

\begin{figure}[ht]
  \centering\includegraphics[height=50pt]{example-image-c}
  \caption{Another figure}\label{fig:caption-c}
\end{figure}

\end{document}

The \label macro is disabled inside \reusefigure, so referencing the reused figure is not possible (but surely not needed).

4
  • 1
    \global\expandafter\let\csname\sfname\endcsname\BODY is much shorter, isn't it?
    – egreg
    Commented Jan 27, 2015 at 11:42
  • Is it possible to have the \reusefigure command prepend the caption with (repeated)? The sourcefigure caption would read: Fig 1.1: my caption The reusefigure caption would read: Fig 1.1 (repeated): my caption. I'm trying to deconstruct your macro but having a hard time interpreting it. I imagine in a similar way that you capture the label the caption can be captured and modified?
    – nicholas
    Commented Aug 12, 2021 at 0:25
  • 1
    @nicholas: Add that detail to the \renewcommand{\thefigure}{...}. I've added an example to my answer.
    – Werner
    Commented Aug 12, 2021 at 2:20
  • That is very helpful thank you @Werner!
    – nicholas
    Commented Aug 12, 2021 at 21:57
0

If you run into problem with \newenvironment macro (needing \protect and \expandafter, etc.), you can try:

\begin{figure}
  \centering
  \includegraphics[height=50pt]{example-image-a}
  \caption{Figure A, initial usage}
  \label{fig:a}
\end{figure}

\begin{figure*}
  \centering
  \includegraphics[height=50pt]{example-image-a}
  \caption*{Figure \ref{fig:A}: Figure A, later usage somewhere else}
\end{figure*}

\begin{figure}
  \centering
  \includegraphics[height=50pt]{example-image-b}
  \caption{Figure B, showing that the second usage of figure A does not increase counter}
  \label{fig:b}
\end{figure}
3
  • 1
    Why do you switch from figure to figure*? That may cause problems in a twocolumn document.
    – TeXnician
    Commented Aug 24, 2017 at 15:34
  • And by the way, this does not replicate the caption on code-level. It's a manual solution after all.
    – TeXnician
    Commented Aug 24, 2017 at 15:37
  • Dear @TeXnician, Case 1, using figure environment, requiring at least two steps: 1. prevent \thefigure from increasing 2. manually referencing the initial usage. Case 2, using figure* environment manually referencing the initial usage in the caption. In both cases, we always have to manually refer to the original usage.
    – Nam Tran
    Commented Oct 24, 2017 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .