0
  1. longtable provides \\* which can prevent the pagebreak, and longtable redefines \hline to support this function.
  2. Then, multirow enhances \cline to support that function.
    One can use package option "longtable" to load the enhancement, see texdoc multirow, sec. 3.6.
  3. It seems that \hhline from hhline package does not work with \\*.

Is there a way to make hhline work with \\*? Maybe this answer can be a start point, but I am not sure.

\documentclass{article}

\usepackage{array}
\usepackage{longtable}
\usepackage[longtable]{multirow}
\usepackage{hhline}
\usepackage[table]{xcolor}

\textheight4\baselineskip
\pdfpageheight5\textheight

\begin{document}
\begin{longtable}{*{3}{|l}|}
    \hline
    A & B                 & C \\ \hline
    A & B                 & C \\ \hline
    A & B                 & C \\* \cline{2-3}
    A & \cellcolor{pink}B & C \\* \cline{2-3}
    A & B                 & C \\ \hline
\end{longtable}

\newpage
\begin{longtable}{*{3}{|l}|}
    \hline
    A & B                 & C \\ \hline
    A & B                 & C \\ \hline
    A & B                 & C \\* \hhline{|~|-|-|}
    A & \cellcolor{pink}B & C \\* \hhline{|~|-|-|}
    A & B                 & C \\ \hline
\end{longtable}
\end{document}

enter image description here

I need to use \cellcolor inside a longtable hence \hhline seems to be a must, by texdoc colortbl, sec. 10.

4
  • 2
    longtable \\* does not prevent page breaks at a following `\hline Commented Jul 29, 2019 at 21:21
  • @DavidCarlisle Then, does multirow actually make \cline working with \\*, as stated in its package doc? Commented Jul 30, 2019 at 0:57
  • I assume so, I don't really use multirow and never looked at its internals. I think I have an answer on this site showing how to have a non-breaking hline in longtable, I will see if I can find..... Commented Jul 30, 2019 at 11:23
  • tex.stackexchange.com/questions/228990/… Commented Jul 30, 2019 at 11:28

1 Answer 1

1

With longtblr environment of tabularray package, \\*, \cline and cell color work as expected:

\documentclass{article}

\usepackage[height=3cm,paperheight=4cm,width=3cm,paperwidth=4cm]{geometry}

\usepackage{tabularray}
\usepackage{xcolor}

\SetTblrTemplate{head,foot}{empty}

\begin{document}

\begin{longtblr}{*{3}{|l}|}
    \hline
    A & B                & C \\ \hline
    A & B                & C \\ \hline
    A & B                & C \\* \cline{2-3}
    A & \SetCell{pink} B & C \\* \cline{2-3}
    A & B                & C \\ \hline
\end{longtblr}

enter image description here

You must log in to answer this question.

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