# label/reference isn't working properly [duplicate]

I am labelling my first table and then referencing it later, but the number that comes up when I reference it is completely different from the one in the caption. I am expecting Table 1, but I am getting Table 1.1. Here are the relevant parts of the table and how I reference the table

\begin{table}
\begin{center}
\begin{tabular}{l r r l r c c c c}

\end{tabular}
\end{center}
\label{table:a}
\caption{This is a cool caption}
\end{table}
Table~\ref{table:firstOne}

• \label must be placed after \caption. This way you use some 'random' counter that was increased by \refstepcounter before, but not the table counter (which is increased by \caption). And \ref{table:a} would work better ;-) – user31729 Oct 12 '15 at 0:20
• You're welcome. This example was easy to reproduce, but please post full examples of code, not fragments only! – user31729 Oct 12 '15 at 0:30

Most likely a section in a book class document is labeled instead of the table itself.

\label must be placed after \caption.

Another issue is the wrong label name used for the reference.

If the table counter format should be changed, use chngcntr package, for example.

\documentclass{book}

\begin{document}

\chapter{First}
\section{First section}

\begin{table}
\centering

\begin{tabular}{l r r l r c c c c}
\end{tabular}
\label{table:a}
\caption{This is a cool caption}

\end{table}

Table~\ref{table:a}  which is actually the section label, but \ref{table:b} is the right label!

\begin{table}
\centering

\begin{tabular}{l r r l r c c c c}
\end{tabular}

\caption{This is another cool caption}
\label{table:b}

\end{table}

\end{document}


Use \centering for having the table centered; the center environment would add unwanted space at top and bottom.

• Two table environments with nested center? Oh, là, là ;-) – egreg Oct 12 '15 at 7:45
• @egreg: I answered quickly ;-) And removed them now – user31729 Oct 12 '15 at 8:55