Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
1  
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
add comment

3 Answers

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
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
add comment

\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
add comment

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
add comment

Your Answer

 
discard

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.