1

I have two figures A and B consisting of subfigures. Some subfigures appear in both of these figures. When I try to refer to the subfigures, the references appear in wrong order. For example:

\begin{document}

Figures \ref{fig:sub1}-\ref{fig:sub3} ...

\begin{figure}[H]
  \centering
  \begin{subfigure}{.5\textwidth}
    \includegraphics[width=\linewidth]{sub1.png}
    \caption{Sub 1.}
    \label{fig:sub1}
  \end{subfigure}
\begin{subfigure}{.5\textwidth}
    \includegraphics[width=\linewidth]{sub2.png}
    \caption{Sub 2.}
    \label{fig:sub2}
  \end{subfigure}
\begin{subfigure}{.5\textwidth}
    \includegraphics[width=\linewidth]{sub3.png}
    \caption{Sub 3.}
    \label{fig:sub3}
  \end{subfigure}
\end{figure}

\begin{figure}[H]
  \begin{subfigure}{.5\textwidth}
    \includegraphics[width=\linewidth]{sub4.png}
    \caption{Sub 4.}
    \label{fig:sub4}
  \end{subfigure}
\begin{subfigure}{.5\textwidth}
    \includegraphics[width=\linewidth]{sub1.png}  % <- appears second time
    \caption{Sub 1.}
    \label{fig:sub1}
  \end{subfigure}
\begin{subfigure}{.5\textwidth}
    \includegraphics[width=\linewidth]{sub5.png}
    \caption{Sub 5.}
    \label{fig:sub5}
  \end{subfigure}
\end{figure}

\end{document}

produces "Figures 2b-1c ..."

How can I get the reference of sub1 to stay as Figure 1a, and not 2b?

  • Welcome to TeX.SE. – Mico Jul 12 at 14:43
1

LaTeX has no direct way of "knowing" that the graph shown in the subfigure that's numbered "1a" gets repeated in the subfigure that's numbered "2b".

For sure, it's not a good idea to employ non-unique \label directives. LaTeX issues the warning message

LaTeX Warning: There were multiply-defined labels

when it encounters, well, multiply-defined labels.

To make it clear to your readers that you wish to cross-reference one and the same graph across two separate subfigure environments (labelled fig:sub1 and fig:sub1_rep, say), you may want to write

Figures \ref{fig:sub1} (also \ref{fig:sub1_rep}) and \ref{fig:sub3}, \dots

in the body of the document. And, to make it extra clear to your readers that the graphs are repeated deliberately, you could write something like \caption{Sub 1, repeated.} the second time the graph occurs.

enter image description here

\documentclass[demo]{article} % omit 'demo' option in real document
\usepackage{graphicx,subcaption}
\begin{document}

\noindent
Figures \ref{fig:sub1} (also \ref{fig:sub1_rep}) and \ref{fig:sub3}, \dots

\begin{figure}[h]
  \begin{subfigure}{.3\textwidth}
    \includegraphics[width=\linewidth]{sub1.png}
    \caption{Sub 1.}
    \label{fig:sub1}
  \end{subfigure}\hfill
  \begin{subfigure}{.3\textwidth}
    \includegraphics[width=\linewidth]{sub2.png}
    \caption{Sub 2.}
    \label{fig:sub2}
  \end{subfigure}\hfill
  \begin{subfigure}{.3\textwidth}
    \includegraphics[width=\linewidth]{sub3.png}
    \caption{Sub 3.}
    \label{fig:sub3}
  \end{subfigure}
\caption{A group of three subfigures}
\end{figure}

\begin{figure}[h!]
  \begin{subfigure}{.3\textwidth}
    \includegraphics[width=\linewidth]{sub4.png}
    \caption{Sub 4.}
    \label{fig:sub4}
  \end{subfigure}\hfill
  \begin{subfigure}{.3\textwidth}
    \includegraphics[width=\linewidth]{sub1.png} % <- appears second time
    \caption{Sub 1, repeated.}
    \label{fig:sub1_rep}
  \end{subfigure}\hfill
  \begin{subfigure}{.3\textwidth}
    \includegraphics[width=\linewidth]{sub1.png}
    \caption{Sub 5.}
    \label{fig:sub5}
  \end{subfigure}
\caption{Another group of three subfigures}
\end{figure}

\end{document}
  • 1
    Thank you, that solved my problem! I don't know how I didn't realize it myself :) But the writing tips are also very useful. – Hessu Jul 13 at 7:10

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.