LaTeX forum ⇒ Graphics, Figures & TablesWeird figure numbering Topic is solved

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

Weird figure numbering

Postby Xorlium » Wed Jan 09, 2013 10:20 pm


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

  1. \pdfoptionpdfminorversion=5
  2. \documentclass[12pt]{article}
  3. \usepackage{amsmath}
  4. \usepackage[demo]{graphicx}
  6. \usepackage{float}
  8. \usepackage{hyperref}
  10. \begin{document}
  12. \section{Intro}
  13. Intro section to show whatever...
  15. \section{Whatever}\label{definitelyNOTouch}
  17. The following should read Figure 1: Figure~\ref{ouch}
  19. But it reads Figure 2!! What is going on???
  21. \begin{figure}[H] \label{ouch}
  22. \begin{center}
  23. \includegraphics{anypic.pdf}
  24. \caption{Some nice caption}
  25. \end{center}
  27. \end{figure}
  29. \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.



User avatar
Stefan Kottwitz
Site Admin
Posts: 9496
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed Jan 09, 2013 10:26 pm


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.

Site admin

User avatar
Posts: 498
Joined: Mon Apr 09, 2007 4:20 pm

Postby sommerfee » Wed Jan 09, 2013 10:28 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.

See also:
Last edited by cgnieder on Wed Jan 09, 2013 11:09 pm, edited 1 time in total.
Reason: added inline code markup

Posts: 2
Joined: Wed Jan 09, 2013 10:16 pm

Postby Xorlium » Thu Jan 10, 2013 6:48 pm

Ah, thanks! It works now :)

Posts: 1
Joined: Wed Mar 26, 2014 5:10 am

Postby sabbaumt » Wed Mar 26, 2014 5:17 am

\section{Electrospun nanofibers as host scaffold for the growth of hierarchical nanostructures}

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.
Can you please help me?

User avatar
Site Moderator
Posts: 4073
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Wed Mar 26, 2014 9:13 am

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

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.

Posts: 1
Joined: Thu Oct 24, 2019 6:46 pm

Postby JB_777 » Thu Oct 24, 2019 7:12 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):

\section{Electrospun nanofibers as host scaffold for the growth of hierarchical nanostructures}

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

User avatar
Ijon Tichy
Posts: 132
Joined: Mon Dec 24, 2018 10:12 am

Postby Ijon Tichy » Sun Oct 27, 2019 10:03 am

:?: \centering does not influence labels or references. Please show a Infominimal 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.

Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: MSN [Bot] and 10 guests