Graphics, Figures & TablesTable without caption but with label

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Isopropyl
Posts: 29
Joined: Thu Sep 24, 2009 10:49 pm

Table without caption but with label

Post by Isopropyl »

Hi,

I am trying to include the number of a table in the table itself. Like this:

Code: Select all

\begin{table}

\begin{tabularx}{\textwidth}{lll}
\toprule
\multicolumn{3}{c}{\textbf{Tabelle \ref{tab1}}}\\
\multicolumn{3}{c}{\textbf{BlaBla}}\\
1 & 2 & 3\\
4 & 5 & 6\\
\bottomrule
\end{tabularx}

\end{table}
The problem now is where to place the

Code: Select all

\label{tab1}
Currently I am doing it like this (excerpt)

Code: Select all

...
\end{tabularx}

\caption{BlaBla\label{tab:PlannedContrasts}}

\end{table}
but that lets me end up with two table captions. One that I included myself in the body of the table (cf. above) and the 'real' latex caption. If, however, I remove the caption, the label will not work anymore and I cannot retrieve the table number.

How could I make the label work without also specifying a caption?

Thank you very much for your help.
Last edited by Isopropyl on Wed Oct 28, 2009 4:28 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Table without caption but with label

Post by sommerfee »

Use \refstepcounter instead of \caption, like here:

Code: Select all

\documentclass{article}
\usepackage{tabularx,booktabs}

\begin{document}

Here comes table number \ref{tabl}:

\begin{table}[!ht]
\refstepcounter{table}\label{tabl}
\begin{tabularx}{\textwidth}{lll}
\toprule
\multicolumn{3}{c}{\textbf{\tablename~\thetable}}\\
\multicolumn{3}{c}{\textbf{BlaBla}}\\
1 & 2 & 3\\
4 & 5 & 6\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}
(Please note that this example uses \thetable instead of \ref{tabl} since a \ref{tabl} would produce a hyperlink to the table itself if the hyperref package is loaded.)

If you need an entry to the list of tables as well, you could use \captionlistentry provided by the caption package instead of \refstepcounter, like here:

Code: Select all

\documentclass{article}
\usepackage{tabularx,booktabs}
\usepackage{caption}

\begin{document}

\listoftables

\bigskip

Here comes table number \ref{tabl}:

\begin{table}[!ht]
\captionlistentry{BlaBlah}\label{tabl}
\begin{tabularx}{\textwidth}{lll}
\toprule
\multicolumn{3}{c}{\textbf{\tablename~\thetable}}\\
\multicolumn{3}{c}{\textbf{BlaBla}}\\
1 & 2 & 3\\
4 & 5 & 6\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}
HTH,
Axel
Isopropyl
Posts: 29
Joined: Thu Sep 24, 2009 10:49 pm

Re: Table without caption but with label

Post by Isopropyl »

Hey, thanks a lot! This is exactly what I was looking for :-)
Post Reply