Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What is the right way to put the caption with longtable?

My numbering starts at 2 and I don't have nested tables. This is corrected if I put \caption{Bla} before \end{longtable}, but it will always insert the caption before the last horizontal line of my table.

\begin{longtable}{ccccc}
\toprule
1&2&3&&\\
\midrule
\endfirsthead

\toprule
1&2&3&&\\
\midrule
\endhead

\hline
\multicolumn{5}{r}{Continued on next page...}\\
\bottomrule
\endfoot
\bottomrule
\endlastfoot
8.8024  &8.8024 &8.8024 &7.2679 &1.3161e+01\\
%A lot more lines here.
9.0364  &9.0364 &9.0364 &7.2678 &1.4124e+01\\
\caption{Caption numbered as 1 but above horizontal line.}
\end{longtable}
share|improve this question
    
Please post a complete minimal working example (MWE) demonstrating the code you have tried. –  Andrew Swann Mar 11 at 13:35
    
as in a normal table, the caption isn't moved it just comes where you use \caption. If you put it as the last row of the table, that's where it will appear. –  David Carlisle Mar 11 at 13:37
    
For a table that spans two or more pages, it's a really good idea to place the caption at the very start, i.e., right after \begin{longtable}{...}. –  Mico Mar 11 at 16:00
add comment

1 Answer 1

up vote 2 down vote accepted

With your current settings, the caption will appear before the last rule is typeset (the last thing that is typeset is what you declare for \endlastfoot which is a horizontal rule while the caption is simply treated as the last row of the table and will then appear before the rule). To get the expected position for the caption, move the \caption to the proper location, for example, after the \bottomrule used in \endlastfoot:

\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}

\begin{document}

\begin{longtable}{ccccc}
\toprule
1&2&3&&\\
\midrule
\endfirsthead
\toprule
1&2&3&&\\
\midrule
\endhead

\hline
\bottomrule
\multicolumn{5}{r}{Continued on next page...}\\
\endfoot
\bottomrule
\caption{Caption numbered as 1 and below horizontal line.}\\
\endlastfoot
8.8024  &8.8024 &8.8024 &7.2679 &1.3161e+01\\
%A lot more lines here.
9.0364  &9.0364 &9.0364 &7.2678 &1.4124e+01\\
\end{longtable}

\end{document}

enter image description here

I did a similar modification to the text "Continued on next page..." so it appears below the horizontal rule at a page break, but you can revert this if desired.

If you want the caption and continuation text at the top (sometimes table captions are required to be before the actual tabel contents), then you can use the \endfirsthead, \endhead commands:

\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}

\begin{document}

\begin{longtable}{ccccc}
\caption{Caption numbered as 1 and above horizontal line.}\\
\toprule
1&2&3&&\\
\midrule
\endfirsthead
\multicolumn{5}{r}{Table~\thetable (Continued)}\\
\toprule
1&2&3&&\\
\midrule
\endhead

\hline
\bottomrule
\endfoot
\bottomrule
\endlastfoot
8.8024  &8.8024 &8.8024 &7.2679 &1.3161e+01\\
%A lot more lines here.
9.0364  &9.0364 &9.0364 &7.2678 &1.4124e+01\\
\end{longtable}

\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.