1

Based on my question How to Fix Longtable Multicolumn that Splitted on the Next Page, now I have this code:

\documentclass[a4paper,oneside,11pt]{book}
\usepackage[hmargin={3cm,2cm},vmargin={2cm,2cm}]{geometry}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage[labelsep=period]{caption}
\titlespacing{\chapter}{0cm}{-1.2cm}{0.7cm}
\titlespacing*{\section}
{0pt}{2ex plus 1ex minus .2ex}{2ex plus .2ex}
\titleformat{\section}
[hang]
{\bfseries}
{\bfseries\thesection}{1ex}{\bfseries}

\begin{document}
    \chapter{Random Text}
    \section{Section Name}
    \lipsum[1]
    \begingroup
    \setcellgapes{5pt}
    \makegapedcells
    \begin{longtable}{|c|c|p{9cm}|}
        \caption{Random text for caption here.}
        \label{table1} \\
        \hline
        \textbf{Head1}&\multicolumn{2}{c|}{\textbf{Head2}}   \\
        \hline
        \endfirsthead
        \caption[]{Random text for caption here. (Continue)} \\
        \hline
        \textbf{Head1}&\multicolumn{2}{c|}{\textbf{Head2}}   \\
        \hline
        \endhead
        \multicolumn{3}{r @{}}{\small\emph{continue on the next page}} \\*
        \endfoot
        \hline
        \endlastfoot
        %%%% table nody    
        1&Text2&Long text here.\\
        \cline{2-3}
        &Text2&\lipsum[4]\\
        \cline{2-3}
        &Text2&Long text here.\\
        \cline{2-3}
        &Text2&Long text here.\\
        \cline{2-3}
        &Text2&Long text here.\\
        \hline
        2&Text2&Long text here.\\
        \cline{2-3}
        &Text2&\lipsum[4]\\
        \cline{2-3}
        &Text2&Long text here.\\
        \cline{2-3}
        &Text2&Long text here.\\
        \cline{2-3}
        &Text2&Long text here.\\
        \hline
    \end{longtable}
    \endgroup
    \section{Section Name 2}
    \lipsum[2]
\end{document}

I want to make the row circled in red on the next page, how to fix it? enter image description here

1 Answer 1

1

The simple solution, you can add \newpage in the row that you want to move in the next page. You can get the last line on previous page move in next page.

\documentclass[a4paper,oneside,11pt]{book}
\usepackage[hmargin={3cm,2cm},vmargin={2cm,2cm}]{geometry}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage[labelsep=period]{caption}
\titlespacing{\chapter}{0cm}{-1.2cm}{0.7cm}
\titlespacing*{\section}
{0pt}{2ex plus 1ex minus .2ex}{2ex plus .2ex}
\titleformat{\section}
[hang]
{\bfseries}
{\bfseries\thesection}{1ex}{\bfseries}

\begin{document}
    \chapter{Random Text}
    \section{Section Name}
    \lipsum[1]
    \begingroup
    \setcellgapes{5pt}
    \makegapedcells
    \begin{longtable}{|c|c|p{9cm}|}
        \caption{Random text for caption here.}
        \label{table1} \\
        \hline
        \textbf{Head1}&\multicolumn{2}{c|}{\textbf{Head2}}   \\
        \hline
        \endfirsthead
        \caption[]{Random text for caption here. (Continue)} \\
        \hline
        \textbf{Head1}&\multicolumn{2}{c|}{\textbf{Head2}}   \\
        \hline
        \endhead
        \multicolumn{3}{r @{}}{\small\emph{continue on the next page}} \\*
        \endfoot
        \hline
        \endlastfoot
        %%%% table nody    
        1&Text2&Long text here.\\
        \cline{2-3}
        &Text2&\lipsum[4]\\
        \cline{2-3}
        &Text2&Long text here.\\
        \cline{2-3}
        &Text2&Long text here.\\
        \cline{2-3}
        &Text2&Long text here.\\
        \hline
        \newpage
        2&Text2&Long text here.\\
        \cline{2-3}
        &Text2&\lipsum[4]\\
        \cline{2-3}
        &Text2&Long text here.\\
        \cline{2-3}
        &Text2&Long text here.\\
        \cline{2-3}
        &Text2&Long text here.\\
        \hline
    \end{longtable}
    \endgroup
    \section{Section Name 2}
    \lipsum[2]
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .