# longtable wrong caption

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

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

\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}

-
Please post a complete minimal working example (MWE) demonstrating the code you have tried. –  Andrew Swann Mar 11 '14 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 '14 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 '14 at 16:00

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
\toprule
1&2&3&&\\
\midrule

\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}


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
\multicolumn{5}{r}{Table~\thetable (Continued)}\\
\toprule
1&2&3&&\\
\midrule

\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}


-