LaTex: Fixing Wrong Figure Numbers

What I tell you right now may save you hours of extensive debugging, cursing under your breath, commenting out custom code dealing with figure layout and much frustration. Whenever you use figures, always (and I mean ALWAYS EVER FOREVER ALWAYS) put \caption first, and \label second like this:

\begin{figure}[htp]
 	\centering
 		\includegraphics{image.eps}
 	\caption{Some Image}
 	\label{fig:some-image}
\end{figure}

If you put the \label above \caption you will run into trouble when referencing figures inside subsections. In my case, the caption underneath the figure would say Fig. 4.2 but the output of \ref would be 4.3.10 because somehow it was picking up the section numbers wrong. The whole damn chapter 4 had the caption/label pairs flipped - but the rest of the document was fine. I have no clue what possessed me to write it this way.

Now I know better. This is the 3 hours of my life that I will never get back. All because I put label before a caption. Do not do that to yourself!

Related Posts:

  • Latex: Rotate Inserted Images
  • LaTex: Making Floatng Text Boxes
  • Latex: Numbered Subsubsections
  • WYSYWIG Users Don’t Save Their Work
  • LaTex Annoyances
  • Installing LaTex on Windows
  • Homeworks From Hell
  • Latex Conditionals
  • Lost and Numbers Stations
  • Latex: Citations in Figures

  • 40 Responses to “LaTex: Fixing Wrong Figure Numbers”

    1. Gravatar Stephane FRANCE Says:

      LOL ! That’s exactly the kind of memory I have from my LaTeX years… ever since then I switched to DocBook, mainly because it’s a much simpler “semantic formating” system when you don’t need picometer precise text formating )

      Posted using Debian IceWeasel 2.0.0.3 on Debian GNU/Linux Debian GNU/Linux
    2. Gravatar Luke UNITED STATES Says:

      I never used DocBook, but it looks interesting. Nice part about it is that you could just post your source file on the web, and style it with CSS for a nice display.

      Here is the thing - how does it deal with mathematical symbols, formulas and etc?

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.3 on Windows Windows XP
    3. Gravatar Stephane FRANCE Says:

      I’ve never played with it (mathematics are far behind me now !) but this might do it :
      http://www.docbook.org/specs/wd-docbook-mathml-1.1CR1.html
      +
      http://www.w3.org/TR/MathML2/

      Let me know if you have a chance to try -)

      Posted using Debian IceWeasel 2.0.0.3 on Debian GNU/Linux Debian GNU/Linux
    4. Gravatar Luke UNITED STATES Says:

      Thanks! I will check it out.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.3 on Windows Windows XP
    5. Gravatar Jack UNITED STATES Says:

      Rock. You saved me, and I only pulled out one clump of hair.

      -Jack

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.3 on Windows Windows XP
    6. Gravatar Luke UNITED STATES Says:

      Awesome! Glad it helped you Jack. It took me a while to figure this out, and I was going nuts over it. Good to know that I saved at least one person from similar fate. )

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.2 on Ubuntu Linux Ubuntu Linux
    7. Gravatar Kieran Says:

      Thank-you so much. I hit on this post from a google search, as I was having this exact problem, and was literally about to embark on “hours of extensive debugging, cursing under your breath, commenting out custom code dealing with figure layout and much frustration”. You have saved me that.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.3 on Linux Linux
    8. Gravatar Luke UNITED STATES Says:

      That’s why I posted this - to save people from this experience. Glad I could help, )

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.2 on Ubuntu Linux Ubuntu Linux
    9. Gravatar mini UNITED STATES Says:

      Luvvvvvvvvvv you dude…was scratching my head the whole day…redrew some of figures not knowing if there was some crappy thing going on with \psfrag or watever…thanks a lot man…

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.4 on Windows Windows XP
    10. Gravatar Steven CANADA Says:

      Thank you for this! You’ve definitely saved me from hours of painful debugging ) I only spent 15 minutes getting frustrated…

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.5 on Ubuntu Linux Ubuntu Linux
    11. Gravatar Ben UNITED STATES Says:

      Thank you! Fortunately, this came up on my google search for “latex \ref troubleshooting.” Otherwise I, like you, would have wasted precious hours.

      Posted using Mozilla Firefox Mozilla Firefox 1.5.0.10 on Linux Linux
    12. Gravatar gehho GERMANY Says:

      …and another one who’s thankful for your hint! Although I have already been debugging for quite a while it at least saved me some more hours of my life! ) Thanks a lot!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.7 on Windows Windows XP
    13. Gravatar marve GERMANY Says:

      yeeeha! you saved me! one day before I have to submit my bachelor-thesis. Of all things, I do not need any trouble with latex today…
      big thanks!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Ubuntu Linux Ubuntu Linux
    14. Gravatar Caio Moritz Ronchi BRAZIL Says:

      Man, you saved me a lot of time with your tip, thank you! I was starting to have Latex…

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.3 on Ubuntu Linux Ubuntu Linux
    15. Gravatar Gabrief ITALY Says:

      THANKS THANKS THANKS THANKS… I’ll save you other 996 ones ^_^ you saved my master thesis!!

      Posted using Opera Opera 9.23 on Windows Windows XP
    16. Gravatar Peter UNITED KINGDOM Says:

      Oh yeah, thanks a lot! I’m really glad that I found your hint. In my first document I switched to manually numbering the figures… ( Now I’m happy with Latex again. )

      Posted using Safari Safari 3.0.3 on Mac OS Mac OS X
    17. Gravatar Marcel SINGAPORE Says:

      Many thanks to your webpage that turned up from a Google search. Previously, I had the same problem but I never did figure out what went wrong. I ended up removing the \ref so that the numbering problem is not apparent.

      Now I know better, all thanks to you. D

      Now back to my #*&$% physics reports…

      Posted using Internet Explorer Internet Explorer 7.0 on Windows Windows XP
    18. Gravatar Mike Says:

      Thanks a ton. I was working on a latex doc and was having this problem. BTW, when you search for “figure numbers wrong in latex” in google, this page comes up as #1. Pretty cool.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.8 on Ubuntu Linux Ubuntu Linux
    19. Gravatar Leo AUSTRIA Says:

      Thanks… wondering about wrong references has already cost me a good deal of my time. Because of my rather mystic appreciation of the LaTeX rendering process (which necessitates such wondrous steps as multiple runs, interleaved with a few calls of BibTeX for good measure), I’ve never been able to figure out, where this problem really originates.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.8 on Ubuntu Linux Ubuntu Linux
    20. Gravatar Luca ITALY Says:

      Thanks man, you saved me a lot of troubles and time.. Two days before my Master’s dissertation deadline!

      A big thanks,
      Luca

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.4 on Ubuntu Linux Ubuntu Linux
    21. Gravatar Rodolphe Courtier UNITED STATES Says:

      Like everyone else, THANKS SO MUCH FOR FIGURING THAT OUT AND POSTING IT. I was on the brink of insanity.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.11 on Windows Windows XP
    22. Gravatar Natalie Schluter IRELAND Says:

      Thank you, thank you, thank you. I was hard-coding the references out of desperation. You are awesome!

      Posted using Internet Explorer Internet Explorer 7.0 on Windows Windows XP
    23. Gravatar iontic SWITZERLAND Says:

      thanks! great post, and great explaination

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.11 on Windows Windows XP
    24. Gravatar Robert JAPAN Says:

      Thankyou! I had the exact same problem, and luckily found this post with a google search. Thanks for saving (at least three) hours of my life!

      Posted using Opera Opera 9.25 on Mac OS Mac OS X
    25. Gravatar JohnFlux UNITED KINGDOM Says:

      You saved me hours!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.10 on Ubuntu Linux Ubuntu Linux
    26. Gravatar Leela UNITED KINGDOM Says:

      Thank you! That is all….

      Posted using Internet Explorer Internet Explorer 6.0 on Windows Windows XP
    27. Gravatar Jim UNITED STATES Says:

      CRAP. Thanks a lot!!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.11 on Ubuntu Linux Ubuntu Linux
    28. Gravatar Tomas SWEDEN Says:

      Another thing on the same topic is that if the \caption command is inside a center environment the numbering will be screwed up if the \label is outside the center environment, even if they are in the correct order.. took me 2 hours to figure this out.. if u hadn’t told me about the order though, I probably would have sat longer =)

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Ubuntu Linux Ubuntu Linux
    29. Gravatar Luke Maciak UNITED STATES Says:

      Oh wow… I never really had that one happen to me. I can kinda see how that would make a huge difference for the latex interpreter, even though it logically shouldn’t matter.

      Thanks for the tip. )

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Ubuntu Linux Ubuntu Linux
    30. Gravatar LD UNITED STATES Says:

      WOO! Thanks Luke! That took 10 minutes instead of 3 hours!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.11 on Linux Linux
    31. Gravatar Luite NETHERLANDS Says:

      Luke, a long list of happy replies. I’ll add to it that you made my day today! I’m going to have a look at your other post with the label “latex” !

      Posted using Mozilla Firefox Mozilla Firefox 3.0b3 on Linux Linux
    32. Gravatar Shannon UNITED STATES Says:

      Dude you are awsome. I have 45 minutes to turn in my thesis and you just saved my ass

      Posted using Internet Explorer Internet Explorer 7.0 on Windows Windows XP
    33. Gravatar Zeeshan PAKISTAN Says:

      thank u very much… I had to submit the document after a few hours n all chapters except chapter 1 had \label above \caption n i was so *&^*&%^&$%* luckily n i found on google search this entry. It helped me n i m really thankful to owner of this blog…. i’ve put this entry to my blog as well )

      Posted using Flock Flock 1.1 on Windows Windows XP
    34. Gravatar Emil SWEDEN Says:

      Thanks for this!
      Saved me a few hours of frustration!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.5 on Fedora Linux Fedora Linux
    35. Gravatar Bayes Bloomington Says:

      Thanks a bunch! I spent about half an hour debugging this and thought someone must have solved this before. Then I found you post!

      Many thanks.. now off to bed.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.14 on Windows Windows XP
    36. Gravatar grace UNITED KINGDOM Says:

      omg thank you YOU!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.13 on Ubuntu Linux Ubuntu Linux
    37. Gravatar Nick Says:

      Excellent advice. It was very kind of you to share your knowledge for free. You should be very proud of yourself. Keep up the good work.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.14 on Windows Windows XP
    38. Gravatar Eirik UNITED STATES Says:

      YES!! After hours of frustration, google finally hit jackpot and I can sleep to night! Thank you!!!

      Posted using Internet Explorer Internet Explorer 6.0 on Windows Windows XP
    39. Gravatar Kim DENMARK Says:

      Best Help EVER!!!!!!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.13 on Windows Windows XP
    40. Gravatar Pankaj UNITED STATES Says:

      You saved my life dude…thanks a ton

      Posted using Opera Opera 9.51 on Windows Windows Vista

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <pre lang=""> <em> <i> <strike> <strong>

    [Quote selected]