For certain styles it appears that the \label statement must be included in \caption to preserve good referencing. Why is that?
- 250,273
-
1Could you give an example? – Daniel Egeberg Jul 26 '10 at 19:24
-
For instance JSS template: http://www.jstatsoft.org/ . – Jul 26 '10 at 19:58
3 Answers
Actually, \label must appear after (not necessarily inside) \caption, because the \caption command increments the counter to which \label's argument associates itself.
- 20,208
- 7
- 27
- 28
-
5+1: exactly. Putting it inside the
\captionadditionally guarantees that it can't get lost. I find myself putting\labels inside\sectioncommands 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.
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.
- 5,352