# Prevent longtable breaking in multirow

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}

-
To avoid the braking, you need to box the content in something that isn't breakable. I would wrap the non-breakable content in a tabular (or tabularx); so, a tabular inside a longtable. –  Werner Jul 27 '12 at 19:36
A tabular inside a longtable will have problem in align the columns –  xucheng Jul 27 '12 at 19:39
The alignments can be fixed if there is a more concrete example, since you can specify the column widths, or adjust the table to suit your needs... just so you know. –  Werner Jul 27 '12 at 19:40
Can the alignments be fixed automatically? Manual adjust multi-columns won't be a good idea. –  xucheng Jul 27 '12 at 19:44
Yes. For example, if you want it in the centre of the table, you can use a tabularx with two X-columns. If you can insert a more concrete example showing some sample data as well as your current problem, a more comprehensive solution that accommodates your needs could be suggested. Either way, it will just provide more scope in terms of the required solution, since you current entries are all equal in width... –  Werner Jul 27 '12 at 19:49

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)

longtable multirow problem with cline and nopagebreak

\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}

-
It world be much better that there is vertical glue to allow the table to break short. Using \pagebreak world force the page break, but when dealing with very long table, I don't know where to put it. –  xucheng Jul 28 '12 at 7:52
yes actually I suspect that if you include the cline patch in the other answer then you won't need the forced break (or you can put \raggedbottom before the table I think –  David Carlisle Jul 28 '12 at 14:07