For some unknown, mysterious reason you can’t put a \cite command as an argument of the \caption statement. I stumbled upon this today when I was trying to attribute an image that I shamelessly snurched from the web.
Apparently, the cause is not as mysterious as I thought. If you want to know why this happens, do some research on fragile commands and moving arguments. Do you need to understand these things throughly? Probably not. You just need to remember that you may sometimes need to protect a \cite when it is an attribute of something else:
\caption{Very Stupid Image \protect\cite{source}}
So here is a new rule of thumb: if you nest a command in an attribute of another command and latex freaks out, you might be dealing with a fragile command inside of a moving attribute. Sticking a \protect in front of the command is a good place to start troubleshooting the problem.
One caveat here – if you put citations in image captions, then they will show up in your list of figures. This looks a little ugly, and it can mess up your citation order. For example, if you use IEEEtran.bst for your BibTex formating, then the first cited source should be [1], second source should be [2] and etc… Unfortunately if your list of figures is on page 3, then the first citation on that page will be counted as [1] even if the actual image does not show up till page 64.
So be careful with these.
I figured out the caption and the list of figures issue. It turns out that \caption can take an optional parameter which is the text for the list like so:
\caption[Stupid Image]{Stupid Image \protect\cite{source}}
If you use it this way the citation only shows up under the figure, but not in the LoF and thus the order of references is preserved.
[tags]latex, fragile commands, moving attributes, cite, caption[/tags]
To fix this annoying problem, load Donald Arseneau’s notoccite.sty package:
http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=notoccite
;)
Heh! It seems that I was not the only person annoyed by this.
For now I’ll stick with defining the list of figures captions separately using the square brace. It makes sense as I can provide a more detailed caption under the image, and use a shorter one for the list.
Thanks a lot! Fixed my referencing for my masters.
You are a hero. Thanks!
\protect\cite{source}
Thanks alot man, the IEEEtran style is full of crap with these kind of things – have been at it since 05:00 this morning…
Thanks! This was useful, especially the last update. :) Bye!
Help me please,
I cannot reference correctly figures in latex, when I write \ref{Fig2} for example i would like to see in the PDF file Figure 2., it doesn’t happen, latex prints Figure 5.
thanks
@ Daniel Bradford: +1 and thank you! Absolutely blew my mind!!
@ Michael Shell:
Good solution, work good for me…