Sign up ×
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.

Possible Duplicate:
Why does an environment’s label have to appear after the caption?

I noticed that when I put the \label command before the \caption command in a figure environment, I get wrong \ref results for this figure. When I put the label in or after the \caption, the \ref will work fine. In the first case, I will get a \ref to the enclosing section (or subsection). Why is that so? And is there some documentation which tells me how to label a figure correctly?

share|improve this question

marked as duplicate by clemens, lockstep, Stefan Kottwitz Oct 16 '12 at 9:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I always put the labels in the captions too. As far as I know the consensus is to do this to ensure proper references. I've seen odd advice for labels in general though. Recently I came across the notion that labels for sections should be in the section command itself, which seems very odd. – qubyte Nov 17 '11 at 9:41
@MarkS.Everitt: Labels should be in the commands. Leslie Lamport says so. :-) – Martin Schröder Nov 17 '11 at 11:34
I really should read the manuals from days of yore! – qubyte Nov 17 '11 at 11:48
Thanks everyone for the insight. As a user I thought that I was putting a label on a figure environment, but instead I am really putting a label on a caption. That's good to know. However I concur with Mark that putting the \label command inside of a \section looks weird. Even if Mr Lamport says so, it does not mean it's the user friendliest solution. :) – Arne Nov 17 '11 at 13:36

1 Answer 1

up vote 22 down vote accepted

The \label always have to be placed after (or within) the caption, as it is \caption that increases the counter related to figures. \label will refer to the last counter that was "active", so by placing it before the caption it will refer to the last sectioning command instead.

share|improve this answer

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