[Tex/LaTex] table breaks spanning multiple pages

multirowpage-breakingsupertabulartables

i'm having an issue with a table that spans multiple pages and breaks across columns that span several rows. my code is listed below. the problem is that on page 1, row 1 shows up with foo1, bar1 and yikes1 with no problem. row 2 and foo2 also shows up on page 1 and then the page breaks, with bar2 and yikes2 ending up on page 2. i want it to break so that all of row 2 end up on the second page. the table will grow and shrink, so i'm hoping for a dynamic solution.

    \begin {supertabular}{|p{1.0in}|p{3.0in}|m{1.10in}|m{1.25in}|}
\hline
col 1
& col 2
& col 3
& col 4
\\\hline
\multirow{4}{*} 
row 1
& foo1
& bar1
& yikes1
\\\cline{2-4}
& foo1
& bar1
& yikes1
\\\cline{2-4}
& foo1
& bar1
& yikes1
\\\cline{2-4}
& foo1
& bar1
& yikes1
\\\cline{2-4}
\\\hline
\multirow{4}{*} 
row 2
& foo2
& bar2
& yikes2
\\\cline{2-4}
& foo2
& bar2
& yikes2
\\\cline{2-4}
& foo2
& bar2
& yikes2
\\\cline{2-4}
& foo2
& bar2
& yikes2
\\\cline{2-4}
\\\hline
\end {supertabular}

Best Answer

This is very very similar to the question longtable multirow problem with cline and nopagebreak. You could also look there how to make a proper MWE ;-)

Compared to this, your code is lacking the following things:

  1. You seem to have \multirow syntax wrong: \multirow{4}{*}{row 1}looks better here.
  2. You need to protect your lines from breaking inside the span of \multirow. Using \\* is a first step.
  3. Still it seems possible for a line to break at a \cline. David gave a patch for this.

With these things in mind, I made the following MWE:

\documentclass{article}

\usepackage{array,supertabular,multirow}

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

\vspace*{15cm}

\begin {supertabular}{|p{1.0in}|p{1.0in}|m{1.10in}|m{1.25in}|}
\hline
col 1
& col 2
& col 3
& col 4
\\\hline
\multirow{4}{*}{row 1}
& foo1
& bar1
& yikes1
\\*\cline{2-4}
& foo1
& bar1
& yikes1
\\\cline{2-4}
& foo1
& bar1
& yikes1
\\*\cline{2-4}
& foo1
& bar1
& yikes1
\\*\cline{2-4}
\\\hline
\multirow{4}{*}{row 2}
& foo2
& bar2
& yikes2
\\*\cline{2-4}
& foo2
& bar2
& yikes2
\\*\cline{2-4}
& foo2
& bar2
& yikes2
\\*\cline{2-4}
& foo2
& bar2
& yikes2
\\*\cline{2-4}
\\\hline
\end {supertabular}

\end{document}

But still I'm getting page breaks :-(

This seems to be a supertabular issue. On a first glance at supertabulars code, I couldn't find an obvious reason for this.

After replacing supertabular by longtable everywhere, it works ;-)