# 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} % \caption IS ALWAYS FIRST \label{fig:some-image} % \label IS ALWAYS SECOND \end{figure}

Easy way to remember this – order your image tags alphabetically. C goes before L. Always. No exception.

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!

This entry was posted in programming and tagged . Bookmark the permalink.

### 256 Responses to LaTex: Fixing Wrong Figure Numbers

1. Thx says:

Thank you very much, saved me a lot of time :D

2. Sören says:

Dude,

I’ll have to add my blessings to the other comments, too.
You’re it, man. Thanks a lot!

3. Steve Pike says:

Thanks for this! Saved me a lot of stress!
-S

4. Steve Pike says:

PS- it is also problematic if you put anyhting between the caption and label:

\caption{Thing I Want To Appear In LOF}
More of what I want under this image
\label{fig:thatone}

Don’t do that either! :)

5. qq says:

Many thanks for this life saver. I’ll go and get the beer for the next 3 hours to celebrate it ;-)

6. doc says:

Thanks mate. I love you (no offence).

7. Nina says:

GOD BLESS YOU.

That is all.

8. Chris says:

Thanks! This thing ***really*** bugged me

9. Hemant says:

Saved my life man. Good onya!

10. bad box says:

aaaargh

thank you. Only 1 hour of my life wasted before I found you.

11. Kommie P. says:

Many thanks for this, I had same problem and just couldn’t figure out what’s going on until I found this article. Thanks!

12. Pan says:

Good God, yes, that’s it! Thank you, thank you, thank you, you saved me from hours of frustration…

Out of curiosity, why does this happen with the figure environment? Has anyone figured this out?

13. Dave says:

Legend! I can finally go to bed now

14. Guy Gur-Ari says:

It’s 5:30 AM, and you’re my favorite person in the whole world.

Cheers

15. Chris says:

2010 and I’m another person who has just been saved by this post. Thanks :)

16. Anish Muttreja says:

Thank you! Wish I had searched Google before trying to debug this.

17. Me says:

You are just … Awesome!!!

18. Lucas says:

I agree with everyone else on this list: thanks for saving me alot of time!

19. Yves says:

Who ever you are, you made my day (or night)!!! BIG UP!!!

20. Nicolas says:

Thank you!
You saved my day!

21. Simarillion says:

Thx, you made my day

22. joost says:

Great tip!
Saved me at least the 3 hours it would have cost me :-)

23. Ryan says:

Thank you so much! May the Lord bless you greatly as you have greatly blessed me with this solution. I am glad that this is such a simple fix, given the understanding that you shared. Thanks again.

24. eve11 says:

Another (late-coming) hint: Don’t include the \caption statement or the \label statement within the \centering tag. I had eg:

\centering{
\includegraphics{graph.pdf}
\caption{here is my caption}
}
\label{here is my label}

And it gave me the same labeling problems. So make sure the caption is outside of the centering bracket.

25. James says:

Thanks so much!!

26. Michael says:

Thank you! In fact, I think I love you.

27. Johanna says:

Thank you!!! Sorry about the 3 hours of your life, but look at how many people you have helped!!!!

28. Lou says:

Cheers mate!

Saved me a lot of hassle. Keep up the good work.

29. Squalo says:

THANKS SO MUCH! I had this problem for last few weeks and this post saved me! THANKS

30. Eli says:

Thanks! This was driving me nuts.

31. THANKS says:

thanks man. saved me some serious headache

32. LJ says:

This bug just cropped up for me (I don’t use LaTeX that much), and this was the first hit on google when I searched “LaTeX Wrong Figure Number”, even though the original post is 3 yrs old. Thanks for the quick fix, it definitely saved me a few hours and plenty of cursing!

33. BA says:

Just to echo previous sentiments…You saved me a chunk of time and hair so thanks very much.

Keno.

34. David says:

Thanks! It sorted my numbering issues, caused by my “well, I do normally put \label and \caption the order way around, but what harm can it do…”!

35. Sanfeliz says:

Dude, thank you. period.

36. Mike says:

Thank you! So glad I read this before wasting any more time. Like you I have several chapters where labels are always after captions, but one chapter where I inexplicably started labelling at the top.

37. mg says:

Thanks man! You definitely saved me some time!

38. David Canada says:

THX > 9000 times, this same “bug” goes for the table reference as well.

39. Thank you says:

Thanks again, for saving us the time! So your 3 hours haven’t been totally useless!

40. Confident again says:

Stumbled upon your post while googling for the same issue. You really saved me hours of pain. Thanks

41. z0nam says:

You saved my life!!

42. Marco says:

Thank you so much!
Saved my day!

43. kagan says:

awesome… u saved my life:)

44. student says:

also interesting is where the problem came from. you know something?

45. Steph says:

Thanks mate! You saved me hours of debugging :)

46. Grzegorz says:

Looks like LaTeX is not as awesome, as some insist it is. But is had wonderful users! Many thanks!!

47. Alex says:

Dude, this didn’t work for me. I’m at the wit’s end here. I’ve made all my figures exactly like you say. My figures in sections are numbered Chapter.#, but if figures are below sections (subsections, subsubsections), they are just #, and they start over each chapter, so I’ve got like, 4 “figure 1’s.” Why? I made sure to put \updateCounters in; can’t think of anything else to try.

48. Mahdi Y.D. says:

I found that another reason may cause wrong numbering in tables and figures.
The caption of figures or tables must not be put between {}, e.g. {\caption{…}}!
:)

49. Joachim says:

Thanks to your entry being the fourth result on google, this just cost me 5 minutes.
Thanks!

50. grateful grant says:

saved me too. thanks a mill!

51. Sandeep says:

Thanks buddy, you saved a lot of time for me :)

52. Steve says:

Merci beaucoup for this post from France!

53. Angelos says:

Thanks a lot for sharing with us :)

54. Soleng says:

Luke, I love you!

55. Jenn says:

Thanks so much =)

56. Amy says:

Thank you sooo much – this was driving me insane :)

57. Duncan McBryde says:

Thanks so much, like so many others here I was about to go crazy and do references manually. Thanks for sharing and making this post easy to find on Google :)

58. william says:

Thank you very much. I had this problem for all the tables in my thesis (figures were fine) and it was driving me crazy.

59. Domschaap says:

Even in the year 2011, you are a hero: saved my first publication. Google and incoherent blogs are a lethal combination!

60. Matt says:

LOL This is an old post, but it just saved me a headache! Thanks!

61. ains says:

you’re my hero!!

62. R Garcia says:

Thanks a lot! I spent way too long on this! Fortunately, I fixed it quickly once I found your post.

63. Leonel says:

Muchas gracias!! a mi también me salvaste!!.

64. Yomna says:

Seriously I don’t know how to thank you!!! My thesis submission is today, and I’ve never faced this problem b4!!!thought I was going crazy or sth.

65. Andreas says:

Thanks man, you saved my day – and my keyboard!!! :-)

66. Kathy says:

This is F***N’ ENORMOUS ERROR IN LATEX!!!!!!!!!!

67. Ah, had exactly the same problem. Thanks for helping out! (and why isn’t this fixed yet in latex, I suppose this is not an intentional ‘feature’ ;))

68. KyleBroflosky says:

69. Lucas says:

I had been changing all kinds of numbering options for 1+ hours without effect.
Thanks google and THANK YOU

70. Johannes says:

You just saved my day with this post, although a couple of years old! Thank you very much!

71. Saha says:

Thanks a lot. Now my figure is number 2 instead of 5, they way it should be. :)

72. Magnesium says:

Thank you! I had label, then centering, then caption….and I swear I have spent the last 20 minutes trying to figure this out.

73. meena says:

Very useful , thank you

74. Jose says:

You are the Mac Daddy bro!

75. Whitney says:

Thanks a million!

76. CS says:

You saved my life..I’m relieved it works now

77. Piotr says:

Thanks!! It is a mystery for me how I managed to write one thesis without stumbling upon that only to get right into it while working on the second one!

78. L T X says:

Thank you! I don’t know why -after a while working with LaTeX- I decided to put my label first… if not by you, I would have spent hours trying to figure out why my captions were wrong!

79. yakx says:

saved my day too ;)

80. Splinter says:

Thank you, you’re my hero!

81. Amir says:

Thank you, thank you, and thank you…
I wrote thesis and paper and both of them had the same problem…
But there are ok now ..

regards,

82. raul says:

Luke,

Thank you. You fixed my problem!

83. DAMN! says:

THANK YOU!

VERY MUCH!

84. Marcin says:

God bless internet and LaTex users who share their knowledge.

85. Jassel says:

This was absolutely the best find ever – thank you, you genius.

86. Klame says:

Four years after and your post is still helping =)

Thanks for sharing !

87. Rodrigo says:

We’re in 2012 and you’re still saving people’s soul. Thanks! :D

88. Cornelius says:

thanks for sharing man I had the exact same problem.

89. amir says:

Thanks man, your certainly saved me on my upcoming paper.

90. Kinh Kha says:

I am compiling a *.tex file with some figures labeled by \label{f3}, \label{f3}, ….
After compiled, Figs are numbered as Fig. 1, Fig. 2, Fig. 3, and Fig. 5, no Fig. 4. :( what is this problem? Please tell me more. Thank you so much.
(In Fig. 3, I have 4 subfigures labeled by f3a, f3b…, so whenever I call Fig. \ref{f3a} I will get Fig. 3a. And If I call Fig. \ref{f3} I will have Fig. 3).

91. sp vanilla says:

Saved us from hours of madness and going berserk

92. Ishrat says:

Thanks a lot… indeed a great help :)

93. Jacek says:

You know what is wrong with LateX? You have remember so much detail and little issues to get it working. This is my story:

I have encountered this error about half a year ago, resolved it, but stopped writing my thesis since I had to make some programming stuff. Now I wanted to return to writing and thought: Hey why these labels are BELOW objects. How idiotic it is. And moved all the labels above. Of course, as you can guess, everything messed up…

I started to look for a solution and found this blog post AGAIN. One of the many LateX ewww’s it is…

THANKS! saved me untold hours of frustration :)

95. Martin says:

Thanks for posting this – Just saved me a lot of frustration!

96. Jacques says:

Haha, thanks! Guess you made me save a lot of (angry) time…

97. Rach says:

Wow, you seriously just solved a problem that was causing me a lot of pain. Best tip ever!

98. Frank Stein says:

Thank you. You’ve literally saved me a lot of debugging. My apologies go now to Knuth’s mother.

99. Ehsan says:

Thanks a LOT! u saved me too! like others. ;)