## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Weird figure numbering Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
Xorlium
Posts: 2
Joined: Wed Jan 09, 2013 10:16 pm

### Weird figure numbering

Hello,

I have no idea what is going on here. I've reduced it to a minimal example:

\pdfoptionpdfminorversion=5\documentclass[12pt]{article}\usepackage{amsmath}\usepackage[demo]{graphicx} \usepackage{float} \usepackage{hyperref} \begin{document} \section{Intro}Intro section to show whatever... \section{Whatever}\label{definitelyNOTouch} The following should read Figure 1: Figure~\ref{ouch} But it reads Figure 2!! What is going on??? \begin{figure}[H] \label{ouch}\begin{center}\includegraphics{anypic.pdf}\caption{Some nice caption}\end{center} \end{figure} \end{document}

Just see what happens. I compile it and it calls the figure "figure 1", but it refers to it as "Figure 2"!! And the link points to the section 2, not figure 1.

I've tried cleaning the help files and recompiling thousands of times, so that's not it. I've also tried this in a different computer with a different OS.

Thanks!

Tags:

Stefan Kottwitz
Posts: 9496
Joined: Mon Mar 10, 2008 9:44 pm
Hi,

welcome to the board!

Just use \label after \caption, this order is important. You will see, it will work fine then. \caption prepares an internal macro which can be used by \label. Without it, \label refers to the anchor before, which is the section here, that's why you got the number 2.

By the way, by simply adding the demo option to graphicx you can ensure that people are able to compile it even without the image. I edited the code line above for you. Now readers can just click the "Open" link above the code and see the output. That's why it's great that you posted a minimal example.

Stefan

sommerfee
Posts: 498
Joined: Mon Apr 09, 2007 4:20 pm
The \label needs to be placed after \caption, otherwise it will reference to the last command which had produced a reference which is \section{Whatever} here.

Last edited by cgnieder on Wed Jan 09, 2013 11:09 pm, edited 1 time in total.

Xorlium
Posts: 2
Joined: Wed Jan 09, 2013 10:16 pm
Ah, thanks! It works now

sabbaumt
Posts: 1
Joined: Wed Mar 26, 2014 5:10 am
\newpage
\section{Electrospun nanofibers as host scaffold for the growth of hierarchical nanostructures}
\begin{figure}[ht]
\centering
\includegraphics[width=0.9\textwidth]{D:/Dharani/Theisis/Thesis/Figures/14.png}
\caption[blah.]{blah.}
\label{fig:14}
\end{figure}

I used the above format and for section 1 it worked but for section 2 it didnt work, it always recalls the image as Fig. 2.2. I dont understand whats going wrong.

Johannes_B
Site Moderator
Posts: 4073
Joined: Thu Nov 01, 2012 4:08 pm
Impossible to tell the reason for the behaviour described. The safest way to find the problem cause, is to prepare a minimal working example and come back here.

Another thing, do you know the difference between \newpage and \clearpage? Maybe the latter is of more use for you.

Best regards
Johannes

BTW: Please insert code into the code-environment, this gives nice markup.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

JB_777
Posts: 1
Joined: Thu Oct 24, 2019 6:46 pm
I had the same problem you were mentioning before.

I could find a solution by just disabling the \centering option, like this (with the "%" symbol):

\newpage
\section{Electrospun nanofibers as host scaffold for the growth of hierarchical nanostructures}
\begin{figure}[ht]
%\centering
\includegraphics[width=0.9\textwidth]{D:/Dharani/Theisis/Thesis/Figures/14.png}
\caption[blah.]{blah.}
\label{fig:14}
\end{figure}

It worked perfectly to me. All the references and ordinal numbers for my figures were right!

Ijon Tichy
Posts: 132
Joined: Mon Dec 24, 2018 10:12 am
\centering does not influence labels or references. Please show a minimal working example.

BTW: You should not use the center environment inside a float like figure or table, because it does add extra vertical space. An indeed if you would use center, the \label has to be in the same group level as the \caption.