8

I am trying to use longtable with repeating headers on each page. For example:

Column 1 & Column 2 & Column 3 \endhead \midrule

results in an ugly multi-page table. The horizontal rule separating the headers from the data appears only on the first page.

In an attempt to fix it:

Column 1 & Column 2 & Column 3 \midrule \endhead

I'd get the following error upon compile:

! Misplaced \noalign.
\midrule ->\noalign 
                    {\ifnum 0=`}\fi \@aboverulesep =\aboverulesep \global \@...
l.6 ...) & Column 2 & Column 3 \midrule
                                                   \endhead

How do I make the horizontal rule also appear on every page?

Here's a screenshot of the part of the manual where \endhead is described: alt text

16

It seems that you simply forgot the double \\

\documentclass{article}
\usepackage{geometry}
\geometry{paperwidth=5cm,paperheight=5cm}%a very small page
\usepackage{longtable,booktabs}
\begin{document}
    \pagestyle{empty}
    \begin{longtable}{ll}
        \caption{My longtable} \\   \toprule
        col 1 &col 2  \\ \midrule
        \endfirsthead
        \toprule
        col 1 & col 2 \\ \midrule
        \endhead
        \hline
        \multicolumn{2}{c}{Continued}\\   \bottomrule
        \endfoot
        \bottomrule
        \endlastfoot
        1 & 2\\   1 & 2\\   1 & 2\\   1 & 2\\   1 & 2\\   1 & 2\\   1 & 2\\   1 & 2\\   
    \end{longtable}

\end{document}

alt text

  • Thanks, @Martin. It wasn't described as such by texdoc longtable. It said "to replace". I'll add a screenshot to make it more informative. – Kit Dec 17 '10 at 16:07
  • 1
    Thank you, that helped me a lot. But when I want all the "content" rows separated by \midrule, I run into trouble with the bottom: If I add a \midrule for the bottom, I get a double line, and if I omit it, I get the equivalent of a \hlinewith its poor spacing to the text... – Lagerbaer May 4 '11 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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