[Tex/LaTex] longtable multirow problem with cline and nopagebreak

longtablemultirowpage-breaking

I have a problem using with the package lontable and multirow together.

It seems that the \* is not avoiding the page breack, if I'm using \cline{i-j} just afterwards.

Here the original code for test.pdf:

\documentclass{article}
\usepackage{longtable}
\usepackage{multirow}
\begin{document}
\begin{longtable}{|c|p{1cm}|p{2cm}|p{5cm}|}
\hline
{} & {\bf ID} & {\bf name} & {\bf short Description} \\ \hline
\multirow{2}{*}{\bf 1} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
....
\multirow{2}{*}{\bf 21} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\multirow{2}{*}{\bf 22} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\multirow{2}{*}{\bf 23} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
....
\multirow{2}{*}{\bf 35} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\end{longtable}
\end{document}

Each record of this table is composed by 2 lines.

The results of this code is to break the record 22 in two pages: first line in page 1 and second line in page 2. That means that \* is not working properly.

\* seems to work correct if I remove \cline{2-4] corresponding to the record 22.
This is the source code:

\documentclass{article}
\usepackage{longtable}
\usepackage{multirow}
\textheight=5\baselineskip
\begin{document}
\begin{longtable}{|c|p{1cm}|p{2cm}|p{5cm}|}
\hline
{} & {\bf ID} & {\bf name} & {\bf short Description} \\ \hline
\multirow{2}{*}{\bf 1} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\multirow{2}{*}{\bf 21} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\multirow{2}{*}{\bf 22} & \multirow{2}{*}{test1} & {name}& {short descrition} \\*
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\multirow{2}{*}{\bf 23} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\multirow{2}{*}{\bf 35} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\end{longtable}
\end{document}

The record 22 is not divided in two pages anymore, but it there is no cline.

How can I maintain the partial horizontal line, and at the same time avoid the pagebreack?

Best Answer

longtable doesn't do anything special with \cline Perhaps it should. This inserts a \nobreak in the right place:

\documentclass{article}
\usepackage{longtable}
\usepackage{multirow}
\textheight=5\baselineskip
\makeatletter
\def\@cline#1-#2\@nil{%
  \omit
  \@multicnt#1%
  \advance\@multispan\m@ne
  \ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
  \@multicnt#2%
  \advance\@multicnt-#1%
  \advance\@multispan\@ne
  \leaders\hrule\@height\arrayrulewidth\hfill
  \cr
  \noalign{\nobreak\vskip-\arrayrulewidth}}
\makeatother
\begin{document}
\begin{longtable}{|c|p{1cm}|p{2cm}|p{5cm}|}
\hline
{} & {\bf ID} & {\bf name} & {\bf short Description} \\ \hline
\multirow{2}{*}{\bf 1} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\multirow{2}{*}{\bf 21} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\multirow{2}{*}{\bf 22} & \multirow{2}{*}{test1} & {name}& {short descrition} \\*
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\multirow{2}{*}{\bf 23} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\multirow{2}{*}{\bf 35} & \multirow{2}{*}{test1} & {name}& {short descrition} \\* \cline{3-4}
& & \multicolumn{2}{c|}{detailed description} \\ \hline
\end{longtable}
\end{document}

So that the breaks happen at \hline only:

enter image description here

Related Question