0

I try to force the pagebreaks only behind \hline and not behind a \hhline{|~|----}

The first MWE shows the wrong behavior

\documentclass[fontsize=12pt,twoside=false]{scrbook}
\usepackage[ngerman]{babel}
\usepackage{hhline}
\usepackage{ltablex}
\usepackage[table]{xcolor}
\usepackage{blindtext} % Just for the MWE

\begin{document}
\blindtext
\blindtext
\blindtext
\blindtext\\
TEXT\\
\begin{tabularx}{\textwidth}{|p{24mm}|p{19.5mm}|p{28.5mm}|p{19mm}|>{\arraybackslash}X|}
\hline
\rowcolor{gray} Test\newline Test\newline Test & Test\newline Test & Test\newline Test\newline Test & Test\newline Test & Test\\
\hline
\endhead
Test & Test & Test & Test & Test\\\hhline{|~|----}
& Test\newline Test & Test & Test\newline Test & Test\\
\hline
Test & Test & Test\newline Test & Test & Test\\\hhline{|~|----} 
& Test\newline Test & Test & Test & Test\\
\hline
Test & Test & Test & Test & Test\\\hhline{|~|----} 
& Test\newline Test & Test\newline Test & Test\newline Test & Test\\
\hline
Test & Test & Test & Test\newline Test & Test\\\hhline{|~|----} 
& Test\newline Test & Test\newline Test & Test\newline Test & Test\\
\hline
\end{tabularx}
\end{document}

enter image description here

The second MWE shows the right behavior

\documentclass[fontsize=12pt,twoside=false]{scrbook}
\usepackage[ngerman]{babel}
\usepackage{hhline}
\usepackage{ltablex}
\usepackage[table]{xcolor}
\usepackage{blindtext} % Just for the MWE

\begin{document}
\blindtext
\blindtext
\blindtext
\blindtext\\
%TEXT\\
\begin{tabularx}{\textwidth}{|p{24mm}|p{19.5mm}|p{28.5mm}|p{19mm}|>{\arraybackslash}X|}
\hline
\rowcolor{gray} Test\newline Test\newline Test & Test\newline Test & Test\newline Test\newline Test & Test\newline Test & Test\\
\hline
\endhead
Test & Test & Test & Test & Test\\\hhline{|~|----}
& Test\newline Test & Test & Test\newline Test & Test\\
\hline
Test & Test & Test\newline Test & Test & Test\\\hhline{|~|----} 
& Test\newline Test & Test & Test & Test\\
\hline
Test & Test & Test & Test & Test\\\hhline{|~|----} 
& Test\newline Test & Test\newline Test & Test\newline Test & Test\\
\hline
Test & Test & Test & Test\newline Test & Test\\\hhline{|~|----} 
& Test\newline Test & Test\newline Test & Test\newline Test & Test\\
\hline
\end{tabularx}
\end{document}

enter image description here

How to force the right behavior automatically?

4
  • 1
    You could try using \* where you do not want a page break to happen and \\ where a page break would be acceptable.
    – leandriis
    Oct 4, 2019 at 5:16
  • What is the purpose of >{\arraybackslash}X, why not simply use X?
    – leandriis
    Oct 4, 2019 at 5:24
  • @leandriis How can I realize your first comment? I get errors if I leave out \` before \hhline{|~|----}` The use of >{\arraybackslash}X is needed in my document but doesn't matter in this MWE.
    – PascalS
    Oct 4, 2019 at 5:54
  • Unfortunately, using \\*\hhline{|~|----} does not seem to work. However, you could switch to \cline{2-5} and use the workaround presented here: tex.stackexchange.com/a/52101/134144
    – leandriis
    Oct 5, 2019 at 12:05

1 Answer 1

1

In the following solution with tabularray package , we define a unbreakable \myhline:

\documentclass[fontsize=12pt,twoside=false]{scrbook}

\usepackage{blindtext} % Just for the MWE
\usepackage{xcolor}
\usepackage{tabularray}
\SetTblrTemplate{head,foot}{empty}
\NewTableCommand{\myhline}{\cline{2-5}\nopagebreak}

\begin{document}

\blindtext
\blindtext
\blindtext

\begin{longtblr}[
  caption = {Long Title},
]{
  colspec = {|p{24mm}|p{19.5mm}|p{28.5mm}|p{19mm}|X|},
  row{1} = {gray8},
  rowhead = 1,
}
\hline
  Test\newline Test\newline Test & Test\newline Test & Test\newline Test\newline Test & Test\newline Test & Test\\
\hline
  Test & Test & Test & Test & Test\\
\myhline
       & Test\newline Test & Test & Test\newline Test & Test\\
\hline
  Test & Test & Test\newline Test & Test & Test\\
\myhline
       & Test\newline Test & Test & Test & Test\\
\hline
  Test & Test & Test & Test & Test\\
\myhline
       & Test\newline Test & Test\newline Test & Test\newline Test & Test\\
\hline
  Test & Test & Test & Test\newline Test & Test\\
\myhline
       & Test\newline Test & Test\newline Test & Test\newline Test & Test\\
\hline
\end{longtblr}

\end{document}

enter image description here

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.