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 '19 at 5:16
  • What is the purpose of >{\arraybackslash}X, why not simply use X? – leandriis Oct 4 '19 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 '19 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 '19 at 12:05

Your Answer

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

Browse other questions tagged or ask your own question.