7

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}
  • 2
    \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 ;-) –  Oct 12 '15 at 00:20
  • You're welcome. This example was easy to reproduce, but please post full examples of code, not fragments only! –  Oct 12 '15 at 00:30

1 Answers1

6

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.