# Where to put the \label on a figure environment? [duplicate]

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?

-
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. –  Mark S. Everitt 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! –  Mark S. Everitt 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
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.