Graphics, Figures & TablesTable legend under table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
albart
Posts: 13
Joined: Mon Jul 06, 2009 12:54 pm

Table legend under table

Post by albart »

Hello,

at this moment, I am struggling to place the legend of a table underneath the table but keeping the title (Table 1, for example) above the table.

In the following code I provide a small table, where the title and the legend both are placed above.

Code: Select all

\documentclass[10pt]{article}

\begin{document}

\begin{table}[h]
\begin{center}
  \caption{Example table}
  \begin{tabular}{ccc}\hline
    1&1&1\\
    2&2&2\\
    3&3&3\\
    \hline
\end{tabular}
\end{center}
\end{table}

\end{document}
Thanks,

Albart

Recommended reading 2024:

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

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

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Table legend under table

Post by gmedina »

Hi,

using a recent version of the caption package, you can use the standard \caption command for the table caption and the \caption* command to typeset the legend. Take a look at the following simple example:

Code: Select all

\documentclass[10pt]{article}
\usepackage{caption}

\begin{document}

\begin{table}[h]
  \centering
  \caption{Example table}
  \begin{tabular}{ccc}\hline
    1&1&1\\
    2&2&2\\
    3&3&3\\\hline
  \end{tabular}
  \caption*{The legeng text goes here.}
\end{table}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
albart
Posts: 13
Joined: Mon Jul 06, 2009 12:54 pm

Table legend under table

Post by albart »

Hi,

thanks for your reply, it solved the point but a new point arose.

Following the article http://www.latex-community.org/index.ph ... Itemid=112, I renewed the @makecaption macro. My code is now as follows:

Code: Select all

\documentclass[10pt]{article}
\usepackage{endfloat}
\usepackage{caption}

\makeatletter
\renewcommand{\@makecaption}[2]{{\centering   \vskip\abovecaptionskip \bfseries #1} #2}
\newcommand{\@makecaptionZ}[2]{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1}%
  \ifdim \wd\@tempboxa >\hsize
    #1\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
\makeatother

\begin{document}



\begin{table}[h]
\begin{center}
  \caption{}
  \begin{tabular}{ccc}\hline
    1&1&1\\
    2&2&2\\
    3&3&3\\
    \hline
\end{tabular}
\caption*{Example table}
\end{center}
\end{table}

\end{document}
Using this code, the title of the table appears above and below the table. It seems that the renewed @makecaption interferes with other definitions. How could I solve this, while keeping a correct formatting of the captions for tables and for figures?

Thanks again,

Albart Coster
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Table legend under table

Post by sommerfee »

Redefining \@makecaption is a bad idea when using the caption package since the caption package comes with a very own version of \@makecaption.

So when using the caption package it's best to try to map all own redefinitions regarding captions to the options of the caption package instead.

So for example
albart wrote: \renewcommand{\@makecaption}[2]{{\centering \vskip\abovecaptionskip \bfseries #1} #2}
looks to me like it could be replaced by

Code: Select all

\captionsetup{singlelinecheck=off,labelfont=bf,labelsep=space}
(BTW: Don't understand what the definition of \@makecaptionZ is good for since it seems not to be used at all.)

Axel
albart
Posts: 13
Joined: Mon Jul 06, 2009 12:54 pm

Re: Table legend under table

Post by albart »

Hello,

thanks! That solved it. I included the part of @makecaptionsZ following the article mentioned, but now I realize that it is not needed. Need to increase my Latex knowledge.

Albart
Post Reply