# 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?

-

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

@MarkS.Everitt: Labels should be in the commands. Leslie Lamport says so. :-) – Martin Schröder Nov 17 '11 at 11:34
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.