Is there any difference between nesting \label in \caption and putting \label outside \caption?

I can't say for sure with ordinary LaTeX, but if you use the showlabels package (very useful when in draft mode) then the label is shown in a different place for the two.

Code:

\documentclass{article}
\thispagestyle{empty}
\usepackage{graphicx}
\usepackage{showlabels}
\begin{document}

\begin{figure}
  \includegraphics{vignettes}      
  \caption{This is a cat.}
  \label{fig:cat}
\end{figure}


\begin{figure}
  \includegraphics{vignettes}      
  \caption{\label{fig:cat}This is a cat.}
\end{figure}
\end{document}

Result:

labels and showlabels


There are no differences from a Latex internal command view. For example the command \addtocontents is defined as

\long\def\addtocontents#1#2{%
    \protected@write\@auxout
        {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
        {\string\@writefile{#1}{#2}}}

In other word \label is made a no-op when \caption or \section pass arguments to the TOC and LOF. The same goes for \markboth, etc. commands to write section headers to the runnings head. On the other hand is the \if@nobreak switch used internaly at a lot of places to prevent \label to cause a page break, for example in the \@afterheading command after a section command. It is clear that LaTeX was designed to put labels inside or after the \caption and \sectionxxx commands.

Note that a label must NOT be put in the short argument of \caption or \section

\caption[\label{xx}Short capt]{Long capt}% DO NOT DO THIS

because the label will diseapear.


EXCEPTION: For footnotes the labels must be inside the footnote itself otherwise it is not defined and will refer to the current active counter, which will probably be a section counter.


As far as I know there are only two differences between coding style A and B:

  1. A is the conventional order of the figure environment.
  2. A is easier to read.