Graphics, Figures & TablesFixing warning associatd with manually defined figure labels.

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
bgreen
Posts: 38
Joined: Wed Nov 22, 2023 11:02 am

Fixing warning associatd with manually defined figure labels.

Post by bgreen »

I repeat this code frequently.

Code: Select all

\begin{figure}[htb]
  \centering
  \begin{subfigure}{0.40\textwidth}
    \includegraphics[width=\linewidth]{ind1_9.jpg}
    \caption{Greenough Interview (Quirk 1971).}
    \label{fig:subfig1}
  \end{subfigure}
  \hfill
  \begin{subfigure}{0.40\textwidth}
    \includegraphics[width=\linewidth]{ind1_10.jpg}
    \caption{Tracks Design page (Unknown 1972). }
        \label{fig:subfig2}
  \end{subfigure}
  \caption{Source: Photos courtesy Tracks magazine.}
  \label{fig:two_images}
\end{figure}
As a result I have over a 1000 warnings (which translates into over 400 figures) , such as:
LaTeX Warning: Label `fig:subfig1' multiply defined.
LaTeX Warning: Label `sub@fig:subfig1' multiply defined.
LaTeX Warning: Label `fig:subfig2' multiply defined.
LaTeX Warning: Label `sub@fig:subfig2' multiply defined.
LaTeX Warning: Label `fig:two_images' multiply defined.
I have two questions. How best to fix this issue? Is it a matter of manually renaming each subfigure1 and subfigure2 to the respective consecutive numbers, from subfig1 and subsfig2, to subfig1000 and subsfig1001? Is there a simpler post hoc way? Sometimes figures have to be moved around in the compiling process, so numbers will be out of consecutive order. Does this matter?

Any advice is appreciated.

Bob

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Fixing warning associatd with manually defined figure labels.

Post by rais »

Hi Bob,

I can't help but wonder...why do you define labels in this manner at all?
It doesn't look like you're referencing any of them---or if you do, the real question should have been ``why do my \ref{whatever} all point to the last use of \label{whatever}?'' or so.
Besides, it would take quite some work keeping track of which label is for which image if it's just ``fig:subfign''---that's bad enough using names like ``fig:interview-greenough'', IMHO.
So if you really don't use \ref or \pageref or any referencing command supplied by an extra package, e.g., by cleveref on any of those labels, discard them.

KR
Rainer
bgreen
Posts: 38
Joined: Wed Nov 22, 2023 11:02 am

Fixing warning associatd with manually defined figure labels.

Post by bgreen »

Hello Rainer,

Many thanks.

I don't use the labels for reference purposes. I am starting from a very low base rate in learning LaTeX, found code to insert figures and copied it. If I can discard them without problem it will save a lot of effort.

Bob
Post Reply