- 我强烈地认为我忽略了显而易见的事情。
- 我有一个
longtable
并希望防止在特定行之后出现分页符。 - 看了手动的并看着这个问题,我认为
\\*
或者\nopagebreak
将会做这项工作。 - 但是,不知何故我没有让以下 MWE 按预期工作:一些标题 C不应“单独”地出现在页面的末尾。
- 我错过了什么?
\documentclass{article}
% "margin = 52mm" is used to control the page break for the MWE.
\usepackage[a4paper, margin = 52mm, landscape]{geometry}
\usepackage{longtable}
\usepackage{booktabs}
\begin{document}
\begin{longtable}{p{0.25\linewidth}p{0.40\linewidth}p{0.25\linewidth}}
% Inspired by % https://tex.stackexchange.com/questions/194150
% --- First Head ---
\caption{Caption.}\\\toprule
\textbf{A} & \textbf{B} & \textbf{C}\\\toprule
\endfirsthead
% --- Other Head ---
\caption*{\textit{Continued from previous page.}}\\\toprule
\textbf{A} & \textbf{B} & \textbf{C}\\\toprule
\endhead
% --- Other Foots ---
\multicolumn{3}{r}{\textit{Continued on next page.}} \\
\endfoot
% --- Last Foot ---
\bottomrule
\endlastfoot
% --- Actual Contents ---
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
\multicolumn{3}{l}{\textbf{Some Header A}}\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
\multicolumn{3}{l}{\textbf{Some Header B}}\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
\multicolumn{3}{l}{\textbf{Some Header C (Should not be before a page break.)}}\\*\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
\multicolumn{3}{l}{\textbf{Some Header D}}\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\
\end{longtable}
\end{document}
实际表格的截图:
答案1
longtblr
这是环境的替代解决方案tabularray
包裹:
\documentclass{article}
% "margin = 54mm" is used to control the page break for the MWE.
\usepackage[a4paper, margin = 54mm, landscape]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{longtblr}[
caption = {Caption},
]{
colspec = {t{0.25\linewidth}t{0.40\linewidth}t{0.25\linewidth}},
rowhead = 1,
row{1} = {font=\bfseries},
}
\toprule
A & B & C \\
\toprule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
\SetCell[c=3]{l}\textbf{Some Header A} & & \\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
\SetCell[c=3]{l}\textbf{Some Header B} & & \\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
\SetCell[c=3]{l}\textbf{Some Header C (Should not be before a page break.)} & & \\*\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
\SetCell[c=3]{l}\textbf{Some Header D} & & \\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\
\bottomrule
\end{longtblr}
\end{document}