![已经找到如何将多页表格内的行拆分到下一页,但需要帮助在顶部和底部行添加水平线](https://linux22.com/image/426097/%E5%B7%B2%E7%BB%8F%E6%89%BE%E5%88%B0%E5%A6%82%E4%BD%95%E5%B0%86%E5%A4%9A%E9%A1%B5%E8%A1%A8%E6%A0%BC%E5%86%85%E7%9A%84%E8%A1%8C%E6%8B%86%E5%88%86%E5%88%B0%E4%B8%8B%E4%B8%80%E9%A1%B5%EF%BC%8C%E4%BD%86%E9%9C%80%E8%A6%81%E5%B8%AE%E5%8A%A9%E5%9C%A8%E9%A1%B6%E9%83%A8%E5%92%8C%E5%BA%95%E9%83%A8%E8%A1%8C%E6%B7%BB%E5%8A%A0%E6%B0%B4%E5%B9%B3%E7%BA%BF.png)
这和我之前的问题有关。我需要拆分包含许多句子和列表的一大行表格。当我发现这个时,我非常兴奋:信用链接。现在,我的问题是我无法在顶行添加行(顶部 1 行,底部 2 行)和最后一行添加 1 行。我有一个糟糕的想法来解决第一个问题,即在顶行下方创建一个空白行,但是垂直长度尺寸太宽,即使它可行,正如我所说,我需要在每一页上重复顶行,而当有分隔行时,这个糟糕的想法将不起作用。
澄清我关于顶部和底部线条的观点。这是我希望表格看起来的样子的示例。
我确实需要你的帮助。提前谢谢!
这是我的 MWE:
\documentclass{article}
\usepackage{lipsum,enumitem}
\usepackage{cals}
\usepackage[latin]{babel}
\showboxbreadth=100
\showboxdepth=100
\usepackage[none]{hyphenat}
\sloppy
\makeatletter
\let\oldDispatch=\cals@row@dispatch
\newbox\rowBefore
\newbox\rowAfter
\newbox\decorationCopy
\newdimen\splitHeight
\def\cals@row@dispatch{%
\cals@ifbreak\iftrue % detect that a break is required
\splitHeight=\pagegoal \advance\splitHeight -\pagetotal
\ifdim \splitHeight>50pt % break inrow only if at least 100pt left
\advance\splitHeight -5pt % avoid pagebreak due to overflows
%
% Split the current row on two: before and after the break
%
\setbox\rowBefore=\hbox{}
\setbox\rowAfter=\hbox{}
\def\next{%
\setbox0=\lastbox
\ifvoid0
\def\next{\global\setbox\rowBefore=\box\rowBefore
\global\setbox\rowAfter=\box\rowAfter }%
\else
\setbox2=\vsplit0 to\splitHeight
\ifvoid0
\setbox0=\vbox{\hbox to \wd2{}}%
\fi
\setbox\rowBefore=\hbox{\box2 \unhbox\rowBefore
\hbox to 0pt{\hss\vbox{\hrule width\wd\cals@current@cs}}}%
\setbox\rowAfter=\hbox{\box0 \unhbox\rowAfter}%
\fi
\next}
\setbox0=\hbox{\unhbox\cals@current@row \next}
%
% Decoration backup, typeset the first row,
% restore context, typeset the second at the end of macro
%
\setbox\decorationCopy=\copy\cals@current@cs
\setbox\cals@current@row=\box\rowBefore
\ht\cals@current@cs=\ht\cals@current@row
\oldDispatch
\cals@issue@break
\cals@thead@tokens
\setbox\cals@current@row=\box\rowAfter
\cals@reheight@cells\cals@current@row
\setbox\cals@current@cs=\box\decorationCopy
\ht\cals@current@cs=\ht\cals@current@row
\let\cals@current@context=b
\fi
\fi
\oldDispatch}
\begin{document}
\begin{calstable}
\colwidths{{150pt}{150pt}}
\thead{\brow \bfseries \cell{\parbox{150pt}{\centering \textbf{Header 1}}}\cell{\parbox{150pt}{\centering \textbf{Header 2}}}
\mdseries \erow}
\brow \cell{\lipsum[ 1]}\cell{\lipsum[ 2]} \erow
\brow \cell{\lipsum[ 4]}\cell{
\begin{itemize}[left= 5pt, noitemsep, topsep= 0pt, nosep]
\item \lipsum[1][1-2]
\item \lipsum[2][1-2]
\item \lipsum[3][1-2]
\item \lipsum[4][1-2]
\end{itemize}} \erow
\brow \cell{\lipsum[ 7]}\cell{\lipsum[ 8]} \erow
\brow \cell{\lipsum[10]}\cell{\lipsum[11]} \erow
\brow \cell{\lipsum[13]}\cell{\lipsum[14]} \erow
\end{calstable}
\end{document}
答案1
您可以通过定义和取消定义(例如)\cals@borderT
行上方(顶部)的规则来覆盖各个行上的规则。这里用于在标题上方放置一条粗规则)也设置\def\cals@rs@width{1pt}
为在行之间提供默认规则。
\documentclass{article}
\usepackage{lipsum,enumitem}
\usepackage{cals}
\usepackage[latin]{babel}
\showboxbreadth=100
\showboxdepth=100
\usepackage[none]{hyphenat}
\sloppy
\makeatletter
\def\cals@rs@width{1pt}\def\cals@cs@width{0pt}
\let\oldDispatch=\cals@row@dispatch
\newbox\rowBefore
\newbox\rowAfter
\newbox\decorationCopy
\newdimen\splitHeight
\def\cals@row@dispatch{%
\cals@ifbreak\iftrue % detect that a break is required
\splitHeight=\pagegoal \advance\splitHeight -\pagetotal
\ifdim \splitHeight>50pt % break inrow only if at least 100pt left
\advance\splitHeight -5pt % avoid pagebreak due to overflows
%
% Split the current row on two: before and after the break
%
\setbox\rowBefore=\hbox{}
\setbox\rowAfter=\hbox{}
\def\next{%
\setbox0=\lastbox
\ifvoid0
\def\next{\global\setbox\rowBefore=\box\rowBefore
\global\setbox\rowAfter=\box\rowAfter }%
\else
\setbox2=\vsplit0 to\splitHeight
\ifvoid0
\setbox0=\vbox{\hbox to \wd2{}}%
\fi
\setbox\rowBefore=\hbox{\box2 \unhbox\rowBefore
\hbox to 0pt{\hss\vbox{\hrule width\wd\cals@current@cs}}}%
\setbox\rowAfter=\hbox{\box0 \unhbox\rowAfter}%
\fi
\next}
\setbox0=\hbox{\unhbox\cals@current@row \next}
%
% Decoration backup, typeset the first row,
% restore context, typeset the second at the end of macro
%
\setbox\decorationCopy=\copy\cals@current@cs
\setbox\cals@current@row=\box\rowBefore
\ht\cals@current@cs=\ht\cals@current@row
\oldDispatch
\cals@issue@break
\cals@thead@tokens
\setbox\cals@current@row=\box\rowAfter
\cals@reheight@cells\cals@current@row
\setbox\cals@current@cs=\box\decorationCopy
\ht\cals@current@cs=\ht\cals@current@row
\let\cals@current@context=b
\fi
\fi
\oldDispatch}
\begin{document}
\begin{calstable}
\colwidths{{150pt}{150pt}}
\thead{\brow
\def\cals@borderT{2pt}
\bfseries \cell{\parbox{150pt}{\centering \textbf{Header 1}}}\cell{\parbox{150pt}{\centering \textbf{Header 2}}}
\mdseries \erow
\let\cals@borderT\relax}
\brow \cell{\lipsum[ 1]}\cell{\lipsum[ 2]} \erow
\brow \cell{\lipsum[ 4]}\cell{
\begin{itemize}[left= 5pt, noitemsep, topsep= 0pt, nosep]
\item \lipsum[1][1-2]
\item \lipsum[2][1-2]
\item \lipsum[3][1-2]
\item \lipsum[4][1-2]
\end{itemize}} \erow
\brow \cell{\lipsum[ 7]}\cell{\lipsum[ 8]} \erow
\brow \cell{\lipsum[10]}\cell{\lipsum[11]} \erow
\brow \cell{\lipsum[13]}\cell{\lipsum[14]} \erow
\end{calstable}
\end{document}