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.

muzimuzhi Z
  • 26,474
  • 2
    longtable \\* does not prevent page breaks at a following `\hline – David Carlisle Jul 29 '19 at 21:21
  • @DavidCarlisle Then, does multirow actually make \cline working with \\*, as stated in its package doc? – muzimuzhi Z Jul 30 '19 at 00: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..... – David Carlisle Jul 30 '19 at 11:23
  • https://tex.stackexchange.com/questions/228990/how-to-use-samepage-environment-in-the-middle-of-a-table/231461#231461 – David Carlisle Jul 30 '19 at 11:28

1 Answers1

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

L.J.R.
  • 10,932