在行表格中分页

在行表格中分页

我想自动生成报告。我使用 python 替换 LaTeX 模板中的占位符。报告包含跨多页的大型复杂表格。我找到了一个数据包cals https://groups.google.com/forum/#!topic/comp.text.tex/gE80AAOQ83U稍加修改即可支持行间分页符。

我现在的问题是,如果一个单元格的内容跨越两页以上,就会出现一个分页符,但实际上应该有两个分页符。有什么办法可以解决这个问题吗?

这是我的示例代码:

\documentclass{article}
\usepackage{lipsum}
\usepackage{cals}
\usepackage[latin]{babel}
\usepackage{blindtext}
\showboxbreadth=100
\showboxdepth=100

\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=\copy2
        \fi
        \setbox\rowBefore=\hbox{\box2 \unhbox\rowBefore}%
        \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}{150pt}}
\thead{\brow \bfseries \cell{header1}\cell{header2}\cell{header3} \mdseries \erow}

\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{\blindtext \blindtext \blindtext} \cell{foo3} \cell{foo3} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow
\brow \cell{foo} \cell{a2} \cell{b2} \erow

\end{calstable}
\end{document}

相关内容