8

I'd like to make a formal longtable in landscape mode. I use booktabs to make the table formal. Here is an example tex document:

\documentclass{article}
\usepackage{array}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{lscape}
\begin{document}
\blindtext[5]
\begin{landscape} \sffamily{%
\begin{longtable}{>{\raggedright}p{7cm}>{\centering}p{7cm}}
\toprule 
Header & \\
\midrule
\endhead
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\bottomrule
\end{longtable}}\end{landscape}
\end{document}

When the document is compiled (pdflatex) the rule (midrule) below the last row (row 10) on page 2 is pushed to the next page, which results in double lines below the header row. Why is this and how could it be fixed?

Edit:

Here's another example, a little bit more complex table which has first header, header, footer and last footer, and shows similar problem. How can I fix this one?

\documentclass{article}
\usepackage{array}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{lscape}

\begin{document}
\blindtext[5]

\begin{landscape} \sffamily{%
\begin{longtable}{>{\raggedright}p{7cm}>{\centering}p{7cm}}
\toprule 
First Header & \\
\midrule
\endfirsthead
\toprule
Header & \\
\midrule
\endhead
Footer & \\
\midrule
\endfoot
Last Footer & \\
\bottomrule
\endlastfoot
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\blindtext[2] & \\
\midrule
\end{longtable}}\end{landscape}
\end{document}

enter image description here

5
  • You've edited the question, and the solution in my answer works in all cases. Mar 6, 2015 at 16:47
  • @karlkoeller Yes, thanks. I edited my question because first there were two other answers which were removed in the meantime. One of the answers solved the first example but not the second one.
    – bcsikos
    Mar 6, 2015 at 18:09
  • Note that the recommendation is to use \bottomrule in \endfoot and remove unnecessary \midrule or \cmidrule{} commands manually. That is, this is what booktabs suggests.
    – cfr
    Mar 7, 2015 at 2:05
  • @karlkoeller Sorry, I clicked the wrong button. If I use \* I occasionally get error message: ! Misplaced \noalign. I found that I have to use tabularnewline to fix this. I tried tabularnewline* and it works but I cannot find any reference to it. Could you please give a link to a reference on tabularnewline?
    – bcsikos
    Mar 9, 2015 at 15:07
  • @bcsikos Using \begin{longtable}{>{\raggedright\arraybackslash}p{7cm} >{\centering\arraybackslash}p{7cm}} you should be able to use \\* without problems. Anyway, here is the link you've requested: tex.stackexchange.com/q/78796/27635 Mar 9, 2015 at 15:26

1 Answer 1

6

You have to use \\* instead of \\. In this way \midrules are kept together with their row.

MWE:

\documentclass{article}
\usepackage{array}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{lscape}
\begin{document}
\blindtext[5]
\begin{landscape} \sffamily{%
\begin{longtable}{>{\raggedright}p{7cm}>{\centering}p{7cm}}
\toprule
Header & \\
\midrule
\endhead
\blindtext[2] & \\*
\midrule
\blindtext[2] & \\*
\midrule
\blindtext[2] & \\*
\midrule
\blindtext[2] & \\*
\midrule
\blindtext[2] & \\*
\midrule
\blindtext[2] & \\*
\midrule
\blindtext[2] & \\*
\midrule
\blindtext[2] & \\*
\midrule
\blindtext[2] & \\*
\midrule
\blindtext[2] & \\*
\bottomrule
\end{longtable}}\end{landscape}
\end{document} 

enter image description here

You must log in to answer this question.

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