这和我之前的问题有关。我需要拆分包含许多句子和列表的一大行表格。当我发现这个时,我非常兴奋:信用链接。现在,我的问题是我无法在顶行添加行(顶部 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}