TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For certain styles it appears that the \label statement must be included in \caption to preserve good referencing. Why is that?

share|improve this question
Could you give an example? – Daniel Egeberg Jul 26 '10 at 19:24
For instance JSS template: jstatsoft.org . – mbq Jul 26 '10 at 19:58
up vote 15 down vote accepted

Actually, \label must appear after (not necessarily inside) \caption, because the \caption command increments the counter to which \label's argument associates itself.

share|improve this answer
+1: exactly. Putting it inside the \caption additionally guarantees that it can't get lost. I find myself putting \labels inside \section commands equally redundantly, for the same reason. – Norman Gray Jul 26 '10 at 20:27

\caption (re)defines a macro \@currentlabel, which \label then uses.

i've recently seen a post from someone who had written something like

{\itshape \caption{foo bar}}\label{foobar}

(anyone with any experience would baulk at that, but it has happened.)

then since \@currentlabel was defined inside a group, \label ended up referring to the last \caption that wasn't inside a group, since the value hadn't been exported from inside the group.

putting \label inside the caption solves the problem for this class of misguided people, in a "robust" way.

for only ordinarily-misguided people, it's enough just to say "put the \label immediately after the \caption (or whatever); don't have spaces or line breaks in between"

the grouping effect applies equally well for sections and other things that can be labelled.

share|improve this answer
The problem is that you must sometimes use a template that messes that up. – mbq Dec 11 '10 at 12:46
Thanks for the extra description of exactly how labeling works. +1. – Dom Mar 7 '11 at 17:10

mbq claims that some templates mess the label system up. if that's so, you just have not to use labels.

fwiw, i've downloaded and scanned the jss stuff that mbq mentioned, and see no indication that label processing is anything other than standard.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.