# Keeping two rows on one page using longtable

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
\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
\multicolumn{3}{l}{\emph{... table \thetable{} continued}} \\
\toprule
Column 1 & Column 2 & Column 3 \\
\midrule
\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}

• 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

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.

• 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
• 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