7

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?

1 Answer 1

6

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.

8
  • thank you. This is however not what I want, as the midrules separate groups of rows and it would be desirable to split the table at the midrules! (but without showing them). Jul 16, 2011 at 8:12
  • 1
    @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, 2011 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, 2011 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. Jul 16, 2011 at 8:56
  • sorry, there is some typo in my last comment: I wanted to say " replace \\ by \\* " Jul 16, 2011 at 9:07

You must log in to answer this question.

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