我尝试强制分页仅有的背后\hline
和不是背后\hhline{|~|----}
第一个 MWE 显示错误的行为
\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}
第二个 MWE 显示了正确的行为
\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}
如何自动强制正确的行为?
答案1
在以下解决方案中tabularray
包中,我们定义一个牢不可破的\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}