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:
April 15th, 2007 at 5:32 am (4129) [Quote]
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 onApril 15th, 2007 at 2:25 pm (4130) [Quote]
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 usingApril 15th, 2007 at 5:09 pm (4131) [Quote]
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 onApril 15th, 2007 at 5:35 pm (4133) [Quote]
Thanks! I will check it out.
Posted usingApril 30th, 2007 at 12:28 pm (4271) [Quote]
Rock. You saved me, and I only pulled out one clump of hair.
-Jack
Posted usingApril 30th, 2007 at 1:10 pm (4272) [Quote]
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 usingMay 15th, 2007 at 6:14 am (4396) [Quote]
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 usingMay 15th, 2007 at 10:44 am (4397) [Quote]
That’s why I posted this - to save people from this experience. Glad I could help,
Posted usingJuly 11th, 2007 at 2:18 am (5162) [Quote]
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 usingJuly 26th, 2007 at 3:56 pm (5443) [Quote]
Thank you for this! You’ve definitely saved me from hours of painful debugging
I only spent 15 minutes getting frustrated…
Posted usingAugust 10th, 2007 at 10:49 am (5583) [Quote]
Thank you! Fortunately, this came up on my google search for “latex \ref troubleshooting.” Otherwise I, like you, would have wasted precious hours.
Posted usingSeptember 25th, 2007 at 5:55 am (6300) [Quote]
…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 usingOctober 3rd, 2007 at 11:17 am (6396) [Quote]
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…
Posted usingbig thanks!
October 6th, 2007 at 4:19 pm (6449) [Quote]
Man, you saved me a lot of time with your tip, thank you! I was starting to have Latex…
Posted usingOctober 11th, 2007 at 12:51 pm (6525) [Quote]
THANKS THANKS THANKS THANKS… I’ll save you other 996 ones ^_^ you saved my master thesis!!
Posted usingOctober 25th, 2007 at 10:03 am (6688) [Quote]
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 usingNovember 3rd, 2007 at 4:36 pm (6813) [Quote]
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.
Now back to my #*&$% physics reports…
Posted usingNovember 3rd, 2007 at 11:16 pm (6822) [Quote]
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 usingNovember 21st, 2007 at 4:10 pm (7077) [Quote]
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 usingDecember 8th, 2007 at 12:26 pm (7314) [Quote]
Thanks man, you saved me a lot of troubles and time.. Two days before my Master’s dissertation deadline!
A big thanks,
Posted usingLuca
December 12th, 2007 at 10:29 pm (7350) [Quote]
Like everyone else, THANKS SO MUCH FOR FIGURING THAT OUT AND POSTING IT. I was on the brink of insanity.
Posted usingDecember 17th, 2007 at 11:50 am (7387) [Quote]
Thank you, thank you, thank you. I was hard-coding the references out of desperation. You are awesome!
Posted usingJanuary 8th, 2008 at 7:23 pm (7646) [Quote]
thanks! great post, and great explaination
Posted usingJanuary 18th, 2008 at 3:44 am (7785) [Quote]
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 usingFebruary 11th, 2008 at 11:04 am (8053) [Quote]
You saved me hours!
Posted usingFebruary 12th, 2008 at 8:26 am (8079) [Quote]
Thank you! That is all….
Posted usingFebruary 16th, 2008 at 4:21 pm (8140) [Quote]
CRAP. Thanks a lot!!
Posted usingFebruary 18th, 2008 at 3:41 pm (8152) [Quote]
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 usingFebruary 18th, 2008 at 3:52 pm (8153) [Quote]
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 usingMarch 5th, 2008 at 2:43 pm (8338) [Quote]
WOO! Thanks Luke! That took 10 minutes instead of 3 hours!
Posted usingMarch 6th, 2008 at 1:12 pm (8363) [Quote]
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 usingMarch 7th, 2008 at 6:16 pm (8385) [Quote]
Dude you are awsome. I have 45 minutes to turn in my thesis and you just saved my ass
Posted usingApril 1st, 2008 at 6:56 am (8640) [Quote]
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 usingApril 13th, 2008 at 9:30 am (8756) [Quote]
Thanks for this!
Posted usingSaved me a few hours of frustration!
April 30th, 2008 at 1:21 am (8922) [Quote]
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 usingMay 4th, 2008 at 9:38 pm (8962) [Quote]
omg thank you YOU!
Posted usingJune 2nd, 2008 at 6:38 am (9199) [Quote]
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 usingJune 2nd, 2008 at 1:17 pm (9205) [Quote]
YES!! After hours of frustration, google finally hit jackpot and I can sleep to night! Thank you!!!
Posted usingJune 14th, 2008 at 7:37 am (9347) [Quote]
Best Help EVER!!!!!!
Posted usingJuly 13th, 2008 at 4:40 am (9598) [Quote]
You saved my life dude…thanks a ton
Posted usingJuly 20th, 2008 at 11:09 pm (9645) [Quote]
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 usingJuly 20th, 2008 at 11:15 pm (9646) [Quote]
Glad I could help guys.
I find these things so that you don’t have to!
Posted usingJuly 22nd, 2008 at 6:02 am (9668) [Quote]
you saved me !!!
Posted usingthanks a lot!
July 27th, 2008 at 7:32 am (9713) [Quote]
Thanks
Saved me a lot frustration
Posted usingAugust 1st, 2008 at 7:15 am (9765) [Quote]
Thank you very much from saving me!
Posted usingAugust 10th, 2008 at 9:20 am (9815) [Quote]
Thanks for this Post!
Posted using Debian IceWeasel 3.0.1 onAugust 13th, 2008 at 5:38 am (9846) [Quote]
god bless you
)
Posted usingAugust 14th, 2008 at 4:06 am (9858) [Quote]
Yeah, cheers dude!
For the record, the label needs to come directly after the caption for it to work properly!
Posted usingSeptember 4th, 2008 at 2:14 pm (10058) [Quote]
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 usingSeptember 8th, 2008 at 3:01 am (10095) [Quote]
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 usingSeptember 11th, 2008 at 5:21 am (10128) [Quote]
I just can repeat the others praises: Thank you very much! You just solved my problem!
Posted usingSeptember 29th, 2008 at 2:40 pm (10276) [Quote]
Thanks! That helped me a lot
Posted usingOctober 15th, 2008 at 11:56 am (10381) [Quote]
I love you man, you saved my day!
Posted using Debian IceWeasel 3.0.1 on