7

I'm trying to tell longtable to only issue a page break at one specific point (by using \\*. Putting a \midrule anywhere near that point causes a page break after the midrule, and not where I want it to be.

Consider this MWE:

\documentclass[12pt,a4paper]{article}

\usepackage{longtable,booktabs}

\begin{document}

\begin{longtable}{c}
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\*
Last line on this page \\
bla \\*%\midrule
bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
\end{longtable}

\end{document}

It produces the correct result:

enter image description here

My problem comes up after uncommenting the \midrule:

enter image description here

I tried preventing the page break after the \midrule by inserting \nopagebreak before and/or after it, but to no avail.

P.S.: I know that right fter a rule would usually be a desired point for a page break in a table. However, I am using rules before and after certain lines to create some kind of seperator between blocks of rows. Thus, the rule must stay on top of the following line and the page brak should occur right after the last \\* before the rule.

6

The problem is not confined to booktabs: Also with a standard \hline you would get a break. longtable redefines \hline so that it actually inserts two lines with a break point between them. This way a line at the bottom of a page is repeated on the top of the next page. You could define you a command which changes the penalty used by the \hline and the width temporarly:

\documentclass[12pt,a4paper]{article}

\usepackage{longtable,booktabs}

\makeatletter

\newlength\oriarrayrulewidth  
\newcount\orilowpenalty
\newcommand\nobreakmidrule{%
 \noalign{\global\oriarrayrulewidth\arrayrulewidth\relax
          \global\orilowpenalty\@lowpenalty\relax  
          \global\@lowpenalty=\numexpr-10000\relax%
          \global\arrayrulewidth\lightrulewidth\relax}
 \hline
 \noalign{\global\@lowpenalty=\orilowpenalty\relax%
          \global\arrayrulewidth\oriarrayrulewidth\relax}}

\makeatother

\begin{document}

\begin{longtable}{c}
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\*
Last line on this page \\
bla \\*\nobreakmidrule
bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
\end{longtable}

\end{document}
  • I have the same problem and this looks interesting, but why are the redefinitions \global? I worry about introducing regressions elsewhere in my document. – meide Jun 22 at 21:37
5

easiest os to force a break where you want a break

\documentclass[12pt,a4paper]{article}

\usepackage{longtable,booktabs}

\begin{document}

\begin{longtable}{c}
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\*
bla \\*
Last line on this page \\
bla \\\pagebreak\midrule
bla \\*
bla \\* bla \\* bla \\* bla \\* bla \\* bla \\* bla \\*
\end{longtable}

\end{document}
  • Thanks! Pretty obvious, but I didn't think of it. :) This will do for now. – einbandi Jun 25 '14 at 19:59

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.