[Tex/LaTex] Prevent longtable breaking in multirow

longtablemultirow

How can I prevent multirow from breaking in longtable environment, so this won't break at wrong position as shown by code below.

\documentclass{article}
\usepackage{multirow,tabularx,ltxtable,filecontents}
\begin{document}
AAAA
\vspace{49em}

\begin{filecontents}{table.tex}
\begin{longtable}{!{\vrule width 1.2pt}c|c|>{\centering\arraybackslash}X!{\vrule width 1.2pt}}
\noalign{\hrule height 1.2pt}
\multirow{2}{*}{A} & B & C\\ \cline{2-3}% I shouldn't break here
 & B & C\\ \hline % I can break here
\multirow{2}{*}{A} & BB & C\\ \cline{2-3}% I shouldn't break here
 & B & C\\
\noalign{\hrule height 1.2pt}
\end{longtable}
\end{filecontents}

\LTXtable{\textwidth}{table.tex}
\end{document}

One more thing, how can I make the hline in breaking position become this:

\noalign{\hrule height 1.2pt}

Best Answer

You can use a combination of the * form of \\ and \nopagebreak to suppress page breaking, and unfortunately (as there is no vertical glue to allow the table to break short) you also need \pagebreak to encourage it to break before the multirow.

You can put the rule in the table foot so it is repeated every page break (you might also want to add some negative space so it fully overlaps any rules in the table body)

see also

longtable multirow problem with cline and nopagebreak

enter image description here

\documentclass{article}
\usepackage{multirow,tabularx,ltxtable,filecontents}
\begin{document}
AAAA
\vspace{49em}

\begin{filecontents}{table.tex}
\begin{longtable}{!{\vrule width 1.2pt}c|c|>{\centering\arraybackslash}X!{\vrule width 1.2pt}}
\noalign{\hrule height 1.2pt}
\endfoot
\noalign{\hrule height 1.2pt}
\multirow{2}{*}{A} & B & C\\* \cline{2-3}% I shouldn't break here
 & B & C\\ \hline % I can break here
\pagebreak
\multirow{2}{*}{A} & BB & C\\* \cline{2-3}% I shouldn't break here
\nopagebreak
 & B & C\\
\end{longtable}
\end{filecontents}

\LTXtable{\textwidth}{table.tex}
\end{document}
Related Question