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

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

    1. Gravatar Stephane FRANCE Says: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      …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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      Thank you! That is all….

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

      CRAP. Thanks a lot!!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.11 on Ubuntu Linux Ubuntu Linux
    28. Gravatar Tomas SWEDEN Says: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      omg thank you YOU!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.13 on Ubuntu Linux Ubuntu Linux
    37. Gravatar Nick Says: Reply to this comment

      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: Reply to this comment

      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: Reply to this comment

      Best Help EVER!!!!!!

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

      You saved my life dude…thanks a ton

      Posted using Opera Opera 9.51 on Windows Windows Vista
    41. Gravatar goodmami UNITED STATES Says: Reply to this comment

      That’s twice in one hour that I’ve googled latex problem and found a link to your site. Thanks for solving my problems )

      Posted using Mozilla Firefox Mozilla Firefox 3.0.1 on Linux Linux
    42. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      Glad I could help guys. ) I find these things so that you don’t have to!

      Posted using Mozilla Firefox Mozilla Firefox 3.0.1 on Windows Windows XP
    43. Gravatar Sebastian GERMANY Says: Reply to this comment

      you saved me !!!
      thanks a lot!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.15 on Linux Linux
    44. Gravatar Christian DENMARK Says: Reply to this comment

      Thanks -)

      Saved me a lot frustration -)

      Posted using Mozilla Firefox Mozilla Firefox 3.0.1 on Mac OS Mac OS X
    45. Gravatar Galiya ITALY Says: Reply to this comment

      Thank you very much from saving me!

      Posted using Safari Safari 3.1.2 on Mac OS Mac OS X
    46. Gravatar Michael GERMANY Says: Reply to this comment

      Thanks for this Post!

      Posted using Debian IceWeasel 3.0.1 on Debian GNU/Linux Debian GNU/Linux
    47. Gravatar izzet TURKEY Says: Reply to this comment

      god bless you ) )

      Posted using Mozilla Firefox Mozilla Firefox 3.0.1 on Linux Linux
    48. Gravatar Speed UNITED KINGDOM Says: Reply to this comment

      Yeah, cheers dude!

      For the record, the label needs to come directly after the caption for it to work properly!

      Posted using Mozilla Firefox Mozilla Firefox 3.0.1 on Windows Windows XP
    49. Gravatar Rob Egginton UNITED KINGDOM Says: Reply to this comment

      Thankyouthankyouthankyou! This has indeed saved me a lot of time. I thought it must be something about ordering, but this got it all sorted very quickly. Thankyou for putting this information on the web.

      Posted using Mozilla Firefox Mozilla Firefox 3.0.1 on Mac OS Mac OS X
    50. Gravatar Saved! UNITED STATES Says: Reply to this comment

      You saved me!

      I sometimes mutter to myself everytime someone says how great Sweave and Latex are that nobody comes saves you when you run into these things….

      Posted using Internet Explorer Internet Explorer 7.0 on Windows Windows Vista
    51. Gravatar Manuela SWITZERLAND Says: Reply to this comment

      I just can repeat the others praises: Thank you very much! You just solved my problem!

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.3 on Linux Linux
    52. Gravatar Knut NORWAY Says: Reply to this comment

      Thanks! That helped me a lot -)

      Posted using Mozilla Firefox Mozilla Firefox 3.0.1 on Windows Windows XP
    53. Gravatar Kristian SWEDEN Says: Reply to this comment

      I love you man, you saved my day!

      Posted using Debian IceWeasel 3.0.1 on Debian GNU/Linux Debian GNU/Linux

    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]