[Tex/LaTex] longtable: how to avoid duplicated midrules below table title

longtablerules

I want to typeset a longtable which is structured by midrules, as the rows are divided in groups.

If it happens (which is in general desirable!) that a group is not split by a page break, in other words a new page of the table starts with a new group, I have duplicated midrules as there is one from the headline definition and one from the table code.

See following example:

\documentclass{scrbook}

\usepackage{booktabs, longtable}

\begin{document}

here comes the table with the pagebreak

\vspace{0.6\textheight}



\begin{longtable}{p{2cm}p{2cm}p{2cm}l}

\toprule
A & B & C & D\\
\midrule
\endfirsthead

\mbox{table continued from last page}\\
\toprule
A & B & C & D\\
\midrule
\endhead
\bottomrule
\mbox{to be continued on following page}
\endfoot
\bottomrule
\endlastfoot

a & b & c & d\\
 & b & c & d\\
 & b & c & d\\
 \midrule
a & b & c & d\\
 & b & c & d\\
 & b & c & d\\
 \midrule
 a & b & c & d\\
 & b & c & d\\
 & b & c & d\\
 \midrule
 a & b & c & d\\
 & b & c & d\\
 & b & c & d\\
\midrule
a & b & c & d\\
 & b & c & d\\
 & b & c & d\\
 \midrule
a & b & c & d\\
 & b & c & d\\
 & b & c & d\\
 \midrule
a & b & c & d\\
 & b & c & d\\
 & b & c & d\\
 \midrule
a & b & c & d\\
 & b & c & d\\
 & b & c & d\\
 \midrule
a & b & c & d\\
 & b & c & d\\
 & b & c & d\\
 \midrule
a & b & c & d\\
 & b & c & d\\
 & b & c & d\\
\end{longtable}

\end{document}

enter image description here

Questions:

  • Is there a way to make LaTeX automatically ignore a second midrule?
  • another way could be to define the table head without midrule and only allow pagebreaks before the midrules – how could I do that?

Best Answer

To disallow page breaking in your groups together with \midrule following them, put * after each \\. i.e. use \\*.

It requires removing \bottomrule in foot (the one after \endhead and before \endfoot), because otherwise you'll get two rules at the end of table on each non-last page.

Related Question