Table caption and label in LaTeX (caption, label)

\caption{text} inside a table environment prints "Table 1: text" and numbers the table. A \label after the caption gives the table a name, and \ref prints its number anywhere in the document.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{booktabs}
\usepackage{caption}

Add a caption and refer to the table

The label name is free; a prefix such as tab: keeps tables apart from figures and sections. The ~ before \ref keeps "Table" and the number on the same line. Compile twice so that the number appears.

\begin{table}
\centering
\begin{tabular}{lr}
\toprule
Item   & Price \\
\midrule
Apple  & 0.50 \\
Banana & 0.25 \\
\bottomrule
\end{tabular}
\caption{Fruit prices in euros}
\label{tab:prices}
\end{table}

Table~\ref{tab:prices} lists the prices.
Result
The compiled example

Open in the editor

Put the caption above the table

Write \caption before the tabular. The standard classes put their 10 pt of space above the caption, so a caption above the table almost touches it. With the caption package loaded, the space goes between caption and table.

\begin{table}
\centering
\caption{Fruit prices in euros}
\label{tab:prices-above}
\begin{tabular}{lr}
\toprule
Item   & Price \\
\midrule
Apple  & 0.50 \\
Banana & 0.25 \\
\bottomrule
\end{tabular}
\end{table}
Result
The compiled example

Open in the editor

Give the list of tables a shorter text

The optional argument of \caption is the text that \listoftables prints. The text in braces stays with the table.

\listoftables

\begin{table}
\centering
\caption[Fruit prices]{Fruit prices in euros, collected at three markets in May}
\begin{tabular}{lr}
\toprule
Item  & Price \\
\midrule
Apple & 0.50 \\
\bottomrule
\end{tabular}
\end{table}
Result
The compiled example

Open in the editor

Caption without a float or without a number

Both commands come from the caption package. \captionof{table}{text} numbers a table that is not inside a table environment, for example in a minipage. \caption*{text} prints a caption without label and number, and without an entry in the list of tables.

\begin{center}
\captionof{table}{Fruit prices in euros}
\label{tab:prices-here}
\begin{tabular}{lr}
\toprule
Item  & Price \\
\midrule
Apple & 0.50 \\
\bottomrule
\end{tabular}
\end{center}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages