1

This question already has an answer here:

When writing I normally don't care if I write first the caption or the label of a figure. A friend recently told me to write always the caption first and then the label.

What reasons are to do this? Are there any advantages by writing it this way?

marked as duplicate by Werner, Maarten Dhondt, Rico, Zarko, user13907 Jan 10 '16 at 19:55

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.

3

Your friend is right. The \label command will store the latest updated counter, which for the figure is done by \caption. In the code below try to move the \label to before the \caption and compile twice. Then it refers to the latest updated counter, in this case the section.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\section{Test section one}
Bla bla 
\section{Test section two}
Bla bla 
\begin{figure}[htb]
  \centering
  \tikz\draw(0,0)rectangle(5,3);
  % \label{fig:one}
  \caption{Test}
  \label{fig:one}
\end{figure}
Bla in Fig~\ref{fig:one}.
\end{document}

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