16

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

lockstep
  • 250,273

3 Answers3

18

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

Phil Miller
  • 20,208
  • 7
  • 27
  • 28
  • 5
    +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
9

\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.

lockstep
  • 250,273
anon
  • 231
0

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.

wasteofspace
  • 5,352