# How to number figures continuously in documentclass{article} [duplicate]

Currently my document labels figures in a continuous manner (figure 1, figure 2, etc.) but references to these same figures have the section, subsection, etc. number in front of it (3.1.1 for a figure in the 3rd section and 1st subsection). I want the references to my figures to number in the same continuous fashion as the figures themselves (i.e. figure 1, figure 2, no matter what section the figures are in). I tried using \counterwithout{figure}{section} and \counterwithout{figure}{subsection} but the 3.1.1 style of figure referencing continues.

Here is a minimum working example that reproduces the problem:

\documentclass{article}
\usepackage{chngcntr}
\counterwithout{figure}{section}
\counterwithout{figure}{subsection}

\usepackage{graphicx}

\begin{document}
\section{section}
\subsection{subsection}

Figure~\ref{fig:foo}
\begin{figure}
\label{fig:foo}
\includegraphics[width=6in]{foo.ps}
\caption{sample text}
\end{figure}

\end{document}

-

## marked as duplicate by Werner, ChrisS, Guido, Thorsten, JesseFeb 15 at 8:23

In article that's the default behaviour, so you don't have to do anything special. In your case you experienced an odd result because you were misplacing \label. Always put \label after \caption in floats (or, inside \caption, but never before it.):

\documentclass{article}
\usepackage[demo]{graphicx}

\begin{document}
\section{section}
\subsection{subsection}

Figure~\ref{fig:foo}
\begin{figure}[!ht]
\includegraphics[width=6in]{foo.ps}
\caption{sample text}
\label{fig:foo}
\end{figure}

\end{document}


The number you are getting is the number of the subsection; you used \label before \caption, so the last anchor (the one of the subsection) was picked to generate the cross-reference.

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

-
You could also place the \label macro inside the \caption macro. That removes having to remember which order they go in. –  Mike Renfro Feb 15 at 1:53
@MikeRenfro true. I've added this remark. Thanks. –  Gonzalo Medina Feb 15 at 1:54