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!
Thank you very much, saved me a lot of time :D
Dude,
I’ll have to add my blessings to the other comments, too.
You’re it, man. Thanks a lot!
Thanks for this! Saved me a lot of stress!
-S
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! :)
Many thanks for this life saver. I’ll go and get the beer for the next 3 hours to celebrate it ;-)
Thanks mate. I love you (no offence).
GOD BLESS YOU.
That is all.
Thanks! This thing ***really*** bugged me
Saved my life man. Good onya!
aaaargh
thank you. Only 1 hour of my life wasted before I found you.
Many thanks for this, I had same problem and just couldn’t figure out what’s going on until I found this article. Thanks!
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?
Legend! I can finally go to bed now
It’s 5:30 AM, and you’re my favorite person in the whole world.
Cheers
2010 and I’m another person who has just been saved by this post. Thanks :)
Thank you! Wish I had searched Google before trying to debug this.
You are just … Awesome!!!
I agree with everyone else on this list: thanks for saving me alot of time!
Pingback: Let’s Learn LaTex: Part 1 « Terminally Incoherent
Who ever you are, you made my day (or night)!!! BIG UP!!!
Thank you!
You saved my day!
Thx, you made my day
Great tip!
Saved me at least the 3 hours it would have cost me :-)
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.
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.
Thanks so much!!
Thank you! In fact, I think I love you.
Thank you!!! Sorry about the 3 hours of your life, but look at how many people you have helped!!!!
Cheers mate!
Saved me a lot of hassle. Keep up the good work.
THANKS SO MUCH! I had this problem for last few weeks and this post saved me! THANKS
Thanks! This was driving me nuts.
thanks man. saved me some serious headache
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!
Just to echo previous sentiments…You saved me a chunk of time and hair so thanks very much.
Keno.
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…”!
Dude, thank you. period.
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.
Thanks man! You definitely saved me some time!
THX > 9000 times, this same “bug” goes for the table reference as well.
Thanks again, for saving us the time! So your 3 hours haven’t been totally useless!
Stumbled upon your post while googling for the same issue. You really saved me hours of pain. Thanks
You saved my life!!
Thank you so much!
Saved my day!
awesome… u saved my life:)
also interesting is where the problem came from. you know something?
Thanks mate! You saved me hours of debugging :)
Looks like LaTeX is not as awesome, as some insist it is. But is had wonderful users! Many thanks!!
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.
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{…}}!
:)
Thanks to your entry being the fourth result on google, this just cost me 5 minutes.
Thanks!
saved me too. thanks a mill!
Thanks buddy, you saved a lot of time for me :)
Merci beaucoup for this post from France!
Thanks a lot for sharing with us :)
Luke, I love you!
Thanks so much =)
Thank you sooo much – this was driving me insane :)
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 :)
Thank you very much. I had this problem for all the tables in my thesis (figures were fine) and it was driving me crazy.
Even in the year 2011, you are a hero: saved my first publication. Google and incoherent blogs are a lethal combination!
LOL This is an old post, but it just saved me a headache! Thanks!
you’re my hero!!
Thanks a lot! I spent way too long on this! Fortunately, I fixed it quickly once I found your post.
Muchas gracias!! a mi también me salvaste!!.
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.
Thanks man, you saved my day – and my keyboard!!! :-)
This is F***N’ ENORMOUS ERROR IN LATEX!!!!!!!!!!
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’ ;))
found this page after hours of bad keyword searching on google.. thank you!
I had been changing all kinds of numbering options for 1+ hours without effect.
Thanks google and THANK YOU
You just saved my day with this post, although a couple of years old! Thank you very much!
Thanks a lot. Now my figure is number 2 instead of 5, they way it should be. :)
Thank you! I had label, then centering, then caption….and I swear I have spent the last 20 minutes trying to figure this out.
Very useful , thank you
You are the Mac Daddy bro!
Thanks a million!
You saved my life..I’m relieved it works now
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!
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!
saved my day too ;)
Thank you, you’re my hero!
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,
Luke,
Thank you. You fixed my problem!
THANK YOU!
VERY MUCH!
God bless internet and LaTex users who share their knowledge.
This was absolutely the best find ever – thank you, you genius.
Four years after and your post is still helping =)
Thanks for sharing !
We’re in 2012 and you’re still saving people’s soul. Thanks! :D
thanks for sharing man I had the exact same problem.
Thanks man, your certainly saved me on my upcoming paper.
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).
Saved us from hours of madness and going berserk
Thanks a lot… indeed a great help :)
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 :)
Thanks for posting this – Just saved me a lot of frustration!
Haha, thanks! Guess you made me save a lot of (angry) time…
Wow, you seriously just solved a problem that was causing me a lot of pain. Best tip ever!
Thank you. You’ve literally saved me a lot of debugging. My apologies go now to Knuth’s mother.
Thanks a LOT! u saved me too! like others. ;)