6

I have been using the \longtable environment and I have an issue with the captions.
All captions appear at the bottom of each part of the table, which is the result I wanted. However, there is a quite annoying wrinkle: only the caption at the bottom of the last part of the table is too close to the table border, and I cannot figure out how to control the spacing within \longtable.

This is the code I have been using:

\begin{document}
\begin{center}
\scriptsize
 \begin{longtable}{|p{2cm}|p{4cm}|p{8cm}|}\hline\hline
 \multicolumn{1}{|p{2cm}|}{\textbf{Text1}} &
 \multicolumn{1}{p{4cm}|}{\textbf{Text2}} &
 \multicolumn{1}{p{8cm}|}{\textbf{Text3}}\\ \hline 
\endfirsthead

\multicolumn{3}{p{3cm}}
{{\bfseries \tablename\ \thetable{} -- continued from previous page}}\\ 
 \hline\multicolumn{1}{|p{2cm}|}{\textbf{Text1}} &
 \multicolumn{1}{p{4cm}|}{\textbf{Text2}} &
 \multicolumn{1}{p{8cm}|}{\textbf{Text3}}\\\hline 
\endhead

\hline \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
\caption[Caption]{Caption}\label{label-caption} 
\endfoot
\caption[Caption]{Caption}\label{label-caption} 
\endlastfoot

\end{longtable}
\end{center}
\end{document}

Any advice is more than welcome! Thanks. I.

4
  • What document class and what other (caption or longtable related) packages are you using?
    – user2574
    Jun 9, 2011 at 6:22
  • @Axel, I am using \documentclass[12pt,a4paper]{report}, \usepackage[float], and \usepackage{longtable} To my understanding, \usepackage[float] takes care of all captions in figures or tables and numbers them accordingly.
    – panza
    Jun 10, 2011 at 18:17
  • please see my edited answer for a possible solution. Jun 10, 2011 at 20:09
  • The float package offers the redesign of existing float types or the definition of new floating environments. Futhermore it offers the float placement "H" for "place it here!". That's all this package does, so it does not take care of captions or numbering of existing floating environments like figure or table. And it does not touch longtable, neither the captions nor the numbering of them.
    – user2574
    Jun 11, 2011 at 6:18

3 Answers 3

5

If you don't mind using the caption package, you can increase the vertical spacing between the table and the caption by using something like the following (change 1em to the value that best suits your needs):

\usepackage[tableposition=below]{caption}
\captionsetup[longtable]{skip=1em}

EDIT: I changed my answer according to Axel's comment.

2
  • 3
    1. By default the longtable package is not using \abovecaptionskip or \belowcaptionskip at all but a \baselineskip below the caption instead. 2. When using the caption package better use the package option tablecaption=b and \captionsetup[longtable]{skip=1em}.
    – user2574
    Jun 9, 2011 at 5:44
  • @Axel Sommerfeldt: thank you for your comments. Initially I deleted my answer, but then I decided to undelete it and edit it according to your suggestion. – Gonzalo Medina Jun 10, 2011 at 20:08
4

you shouldn't use the center-environment. You get additional space between the text and the table. longtable has an optional argument which controls the horizontal alignment.

I can't see any problems?

\documentclass{scrartcl}
\usepackage{longtable}
\usepackage{ltcaption}
\usepackage{showframe,lipsum}

\begin{document}
\lipsum[1]
\begin{scriptsize}
 \begin{longtable}{|p{2cm}|p{4cm}|p{8cm}|}\hline\hline
 \multicolumn{1}{|p{2cm}|}{\textbf{Text1}} &
 \multicolumn{1}{p{4cm}|}{\textbf{Text2}} &
 \multicolumn{1}{p{8cm}|}{\textbf{Text3}}\\ \hline 
\endfirsthead

\multicolumn{3}{p{3cm}}
{{\bfseries \tablename\ \thetable{} -- continued from previous page}}\\ 
 \hline\multicolumn{1}{|p{2cm}|}{\textbf{Text1}} &
 \multicolumn{1}{p{4cm}|}{\textbf{Text2}} &
 \multicolumn{1}{p{8cm}|}{\textbf{Text3}}\\\hline 
\endhead

\hline \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
\caption[Caption]{Caption}\label{label-caption} 
\endfoot
\caption[Caption]{Caption}\label{label-caption} 
\endlastfoot

\end{longtable}
\end{scriptsize}

\clearpage
\lipsum[1]
\begin{center}
\scriptsize
 \begin{longtable}{|p{2cm}|p{4cm}|p{8cm}|}\hline\hline
 \multicolumn{1}{|p{2cm}|}{\textbf{Text1}} &
 \multicolumn{1}{p{4cm}|}{\textbf{Text2}} &
 \multicolumn{1}{p{8cm}|}{\textbf{Text3}}\\ \hline 
\endfirsthead

\multicolumn{3}{p{3cm}}
{{\bfseries \tablename\ \thetable{} -- continued from previous page}}\\ 
 \hline\multicolumn{1}{|p{2cm}|}{\textbf{Text1}} &
 \multicolumn{1}{p{4cm}|}{\textbf{Text2}} &
 \multicolumn{1}{p{8cm}|}{\textbf{Text3}}\\\hline 
\endhead

\hline \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
\caption[Caption]{Caption}\label{label-caption} 
\endfoot
\caption[Caption]{Caption}\label{label-caption} 
\endlastfoot

\end{longtable}
\end{center}

\end{document}
1
  • thank you very much for your help. I am currently using \documentclass[12pt,a4paper]{report}, \usepackage[float], and \usepackage{longtable} in my preamble, and it does not seem to work for me. You seems to include \center in your example, would it be of any problem to see what kind of output your compilation returns? Thanks indeed, I.
    – panza
    Jun 10, 2011 at 18:37
0

I just added

\caption{\label{tab:tab1} Some text in caption}\\ 

just after the environment declaration.

\begin{longtable}{|p{5cm}|p{5cm}|p{5cm}|}
\caption{\label{tab:tab1} Some text in caption}\\
...
\end{longtable}

That's adapted from the chapter 8 of documentation found here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .