xltabular:防止或建议分页符

xltabular:防止或建议分页符

xltabular 是否支持 \nopagebreak 或 \pagebreak?我尝试添加它以防止在第 11 行和第 12 行之间分页,但没有成功。

\documentclass{article}

\usepackage{xltabular}

\title{xltabular}

\begin{document}

\begin{xltabular}{\textwidth}{|l|X|X|}
\caption{A sample long table.} \label{tab:long} \\

\hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
\endfirsthead

\multicolumn{3}{c}%
{\tablename\ \thetable{} -- continued from previous page} \\
\hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
\endhead

\hline \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
\endfoot

\hline
\endlastfoot

Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\  \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 11 & & \\ \cline{2-3} 
Line 12 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\  \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline

\end{xltabular}



\end{document}

答案1

另一种选择:使用版本 2021M(2021-08-01)的tabularray软件包,您可以在环境中对和同时使用\\*、和。\nopagebreak\pagebreak\hline\clinelongtblr

\documentclass[12pt]{article}

\usepackage[a6paper,margin=10mm]{geometry}
\pagestyle{empty}
\usepackage{tabularray}

\begin{document}

\begin{longtblr}[
  caption = {Long Tabular},
  entry = {Short Caption},
  label = {tblr:abcd},
]{
  colspec = {XXX}, width = 0.9\linewidth,
  rowhead = 2, rowfoot = 1
}
\hline
 Head & Head & Head \\
\hline                               
 Head & Head & Head \\
\hline
 Alpha   & Beta  & Gamma   \\
\hline
 Epsilon & Zeta  & Eta     \\
\hline
 Iota    & Kappa & Lambda  \\
\hline
 Nu      & Xi    & Omicron \\
\hline
 Rho     & Sigma & Tau     \\
\hline
 Phi     & Chi   & Psi     \\
\hline
 Alpha   & Beta  & Gamma   \\
\hline
 Epsilon & Zeta  & Eta     \\
\hline
 Iota    & Kappa & Lambda  \\
\hline
 Nu      & Xi    & Omicron \\
\hline
 Rho     & Sigma & Tau     \\
\hline
 Phi     & Chi   & Psi     \\
\hline
 Alpha   & Beta  & Gamma   \\\nopagebreak
\cline{2-3}
 Epsilon & Zeta  & Eta     \\*
\cline{2-3}
 Iota    & Kappa & Lambda  \\
\hline
 Nu      & Xi    & Omicron \\
\hline
 Rho     & Sigma & Tau     \\
\hline
 Phi     & Chi   & Psi     \\
\hline
 Alpha   & Beta  & Gamma   \\
\hline
 Epsilon & Zeta  & Eta     \\
\hline
 Iota    & Kappa & Lambda  \\
\hline
 Nu      & Xi    & Omicron \\
\hline
 Rho     & Sigma & Tau     \\
\hline
 Phi     & Chi   & Psi     \\
\hline
 Alpha   & Beta  & Gamma   \\
\cline{2-3}\pagebreak
 Epsilon & Zeta  & Eta     \\
\hline
 Iota    & Kappa & Lambda  \\
\hline
 Nu      & Xi    & Omicron \\
\hline
 Rho     & Sigma & Tau     \\
\hline
 Phi     & Chi   & Psi     \\
\hline
 Alpha   & Beta  & Gamma   \\
\hline
 Epsilon & Zeta  & Eta     \\
\hline
 Iota    & Kappa & Lambda  \\
\hline
 Nu      & Xi    & Omicron \\
\hline
 Rho     & Sigma & Tau     \\
\hline
 Phi     & Chi   & Psi     \\
\hline
 Alpha   & Beta  & Gamma   \\
\hline
 Epsilon & Zeta  & Eta     \\
\hline
 Iota    & Kappa & Lambda  \\
\hline
 Nu      & Xi    & Omicron \\
\hline
 Rho     & Sigma & Tau     \\
\hline
 Phi     & Chi   & Psi     \\
\hline
 Foot & Foot & Foot \\
\hline
\end{longtblr}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.

\end{document}

答案2

你可以添加一个\nobreak\cline这样它就不会在 cline 之后中断

\documentclass{article}

\usepackage{xltabular}
\makeatletter
\def\@cline#1-#2\@nil{%
  \omit
  \@multicnt#1%
  \advance\@multispan\m@ne
  \ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
  \@multicnt#2%
  \advance\@multicnt-#1%
  \advance\@multispan\@ne
  \leaders\hrule\@height\arrayrulewidth\hfill
  \cr
  \noalign{\nobreak\vskip-\arrayrulewidth}}%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\makeatother
\title{xltabular}

\begin{document}

\begin{xltabular}{\textwidth}{|l|X|X|}
\caption{A sample long table.} \label{tab:long} \\

\hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
\endfirsthead

\multicolumn{3}{c}%
{\tablename\ \thetable{} -- continued from previous page} \\
\hline \multicolumn{1}{|c|}{\textbf{First column}} & \multicolumn{1}{c|}{\textbf{Second column}} & \multicolumn{1}{c|}{\textbf{Third column}} \\ \hline 
\endhead

\hline \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
\endfoot

\hline
\endlastfoot

Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\  \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 11 & & \\* \cline{2-3}
Line 12 & & \\ \hline
Line 1 & & \\ \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\  \cline{2-3} 
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline
Line 1 & & \\
Line 2 & & \\ \hline

\end{xltabular}



\end{document}

答案3

我找到了两个适用于 MWE 的简单选项。无一修改表文件。

(1)在标题行中添加一个非常小的垂直空间,以鼓励尽早休息。\vspace*{2pt}就行。

(2)将单元格扩展至不可察觉的量,例如,在\renewcommand{\arraystretch}{1.005}之前添加\begin{xltabular},以形成完整的第一页表格。

b

\caption{A sample long table.} \label{tab:long} \vspace*{2pt}\\ 

或者

{\renewcommand{\arraystretch}{1.005}
\begin{xltabular}{\textwidth}{|l|X|X|}
...
\end{xltabular}}

相关内容