0

I am trying to find a way to make sure that a long table doesn't break when spanning multiple pages.

I tried using long table with multirow but the page is splitting the table. By splitting I mean either the tabular row2 at the end of the first page goes entirely to the next page or take it to the previous page. Is there anyway to have this incorporated here?

\usepackage{longtable}

\begin {longtable}{|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
\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
\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
\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
\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
\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
\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 {longtable}

I am getting the results as indicated in the attached screenshots

enter image description here

enter image description here

0

One of the solution that I think will work here to insert the portion to the table where we want to split it.

\pagebreak
\hline

If there is some other way, please feel free to post in the answers.

0

Although this does not directly answer your question, here is nevertheless a suggestion/something to consider: I would avoid the combination of \multirow with longtable as it might not only lead to the multirow cell being split over two pages but could also cause the multirow text to overlap with the footer/ page number (See for example here: longtable cut text overlapping with footnote) I thus suggest the following redesign of the table in which the text you originally placed in multirow is now placed in a multicolumn to act like some kind of sub-header in the table. (See also this answer: https://tex.stackexchange.com/a/565576/134144 in which I applied a similar technique.) With the use of \\* you can then prevent a pagebreak after between specific rows. enter image description here

\documentclass{article}
\usepackage{longtable}
\usepackage{array}
\usepackage{booktabs}
\begin{document}

\null\vspace{9cm}
\begin {longtable}{@{\qquad}p{1.0in}p{1.10in}p{1.25in}}
\toprule
 col 2
& col 3
& col 4
\\
\midrule
\multicolumn{3}{l}{row 1}\\*
 foo1
& bar1 bar1 bar1 bar1
& yikes1 yikes1 yikes1 yikes1 yikes1 yikes1 yikes1
\\*
 foo1
& bar1
& yikes1
\\*
 foo1
& bar1
& yikes1
\\*
 foo1
& bar1
& yikes1
\\
\midrule
\multicolumn{3}{l}{row 2}\\*
 foo1
& bar1 
& yikes1 
\\*
 foo1
& bar1
& yikes1
\\*
 foo1
& bar1
& yikes1
\\*
 foo1
& bar1
& yikes1
\\
\midrule
\multicolumn{3}{l}{row 3}\\*
 foo1
& bar1 
& yikes1 
\\*
 foo1
& bar1
& yikes1
\\*
 foo1
& bar1
& yikes1
\\*
 foo1
& bar1
& yikes1
\\
\midrule
\multicolumn{3}{l}{row 4}\\*
 foo1
& bar1 
& yikes1 
\\*
 foo1
& bar1
& yikes1
\\*
 foo1
& bar1
& yikes1
\\*
 foo1
& bar1
& yikes1
\\
\midrule
\\\hline

\end {longtable}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.