13

I am creating a longtable which spreads over multiple pages. The problem is that the coefficients and standard errors which are in two consequential rows sometimes get separated. How to I hold those two rows together (i.e. on one page)?

So for example image that you want the AAAAA and CC row to be always to be packed together (AAAA always followed by CC). Now the last row in this table (on the first page) is AAAA but I want it to be together with the first row on the next page. One solution would be to put a pagebreak before the last AAAA (on the first page) but I need a general solution because I am producing lots of tables like this (automatically).

\documentclass{article}

\usepackage[referable]{threeparttablex}
\usepackage{longtable}
\usepackage{booktabs}

\begin{document}

\begin{ThreePartTable}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{TableNotes}[flushleft]
\item[a] \label{tn:a} \footnotesize test test test test test test test test
\item[b] \label{tn:b} test2
\item Test
\source Made up by daleif
\end{TableNotes}
\begin{longtable}{@{\extracolsep{4pt}}l*{2}{c}@{}}
\caption{A long table that goes on and on and ....}\\
\toprule
Column 1 & Column 2 & Column 3 \\
\midrule
\endfirsthead
\multicolumn{3}{l}{\emph{... table \thetable{} continued}} \\
\toprule
Column 1 & Column 2 & Column 3 \\
\midrule
\endhead
\midrule
\multicolumn{3}{r}{\emph{Continued on next page...}}\\
\endfoot
\bottomrule
\insertTableNotes\\
\endlastfoot
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\          
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\        
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\         
  CC   &          & DD  \\
AAAA & XXXXXXXX & BBBB \\
AAAA\tnotex{tn:a} & XXXXXXXX & BBBB \\
  CC   &          & DD\tnotex{tn:b}   \\
\end{longtable}
\end{ThreePartTable}

\end{document}
  • 1
    Use \\* between lines that you want to keep together. – egreg Jun 4 '13 at 19:50
  • You might also try to put the 'xxxxxx' in a multirow that spans two rows. – Andy Clifton Jun 5 '13 at 4:13
16

You can prohibit a page break between two rows by ending the first with

\\*

Thus

AAAA & XXXXXXXX & BBBB \\*
  CC   &          & DD  \\

should be what you're looking for.

  • 1
    In terms of quoting sources, should point out that this is in the longtable documentation (search for \\* or \nopagebreak): mirrors.ctan.org/macros/latex/required/tools/longtable.pdf – Stuart Rossiter Apr 14 '14 at 11:39
  • @monsieurRigsby Thanks for the comment. The \\* combination has the same meaning also in other “standard” contexts, such as flushleft, center and flushright environments (where page breaks are allowed). It means nothing different from \\ in tabular. – egreg Apr 14 '14 at 11:42
  • 2
    The \\* command does not seem to work if there is an \hline between the rows. – MunHo Oct 23 '16 at 19:59
  • How would you do it in a xtabular environment? tex.stackexchange.com/q/380864/108331 – Benjamin Jul 17 '17 at 17:55
  • @Benjamin I'd not consider xtabular to be satisfying the minimal requirements. – egreg Jul 17 '17 at 19:17

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.