# longtable: how to avoid duplicated midrules below table title?

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

\mbox{table continued from last page}\\
\toprule
A & B & C & D\\
\midrule
\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}


## 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?
-

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.
@Martin: I've updated the answer. Sorry, I somehow missed the grouping part and focused on preserving \midrule on the current page, because I had similar problem some time ago, but I was using \midrule after each row and that is why I gave you wrong solution at first. –  przemoc Jul 16 '11 at 8:25
@Martin: Once again updated. Well, Herbert provided \\* before me, but I found it independently checking longtable doc. I am really ashamed that previously when I was solving similar problem myself I didn't noticed the \\* part... –  przemoc Jul 16 '11 at 8:40
no need to be ashamed!! Thank you very much for this elegant and easy solution (I did not know about the star version \\* and it makes thinks very easy, as in those tables with grouped rows I just have to replace \ by \* and let the ˚\midrules` allow pagebreaks. –  Martin Jul 16 '11 at 8:56