我正在使用 OPmac 宏来处理 tcolorbox 中的多列,如下所建议: tcolorbox 可破坏框内的多列
到目前为止,它运行得很好,但我遇到了一个问题。每当我想从普通文本切换到两列文本(不适合一页)时,页面上的剩余空间就不会被使用。相反,两列文本从下一页开始。如果文本对于此页面来说也太大,它会形成正常的分页符。这个问题也发生在 tcolorbox 之外。有没有办法让列在普通文本之后立即开始并在页面末尾中断?
\documentclass[11pt, oneside, a4paper]{report}
\usepackage{lipsum}
\newdimen\colsep \colsep=2em
\newcount\mullines
\newcount\tmpnum
\def\corrsize #1{%% #1 := #1 + \splittopskip - \topskip
\advance #1 by \splittopskip \advance #1 by-\topskip
}
\def\begmulti #1 {\par\bgroup\penalty0 \def\Ncols{#1}
\setbox6=\vbox\bgroup\penalty0
%% \hsize := Sirka sloupce = (\hsize+\colsep) / n - \colsep
\advance\hsize by\colsep
\divide\hsize by\Ncols \advance\hsize by-\colsep
\mullines=0
\def\par{\ifhmode\endgraf\global\advance\mullines by\prevgraf\fi}%
}
\def\endmulti{\vskip-\prevdepth\vfil
\expandafter\egroup\expandafter\baselineskip\the\baselineskip\relax
\dimen0=.8\maxdimen \tmpnum=\dimen0 \divide\tmpnum by\baselineskip
\splittopskip=\baselineskip
\setbox1=\vsplit6 to0pt
%% \dimen1 := the free space on the page
\vsize=.95\vsize
\ifdim\pagegoal=\maxdimen \dimen1=\vsize \corrsize{\dimen1}
\else \dimen1=\pagegoal \advance\dimen1 by-\pagetotal \fi
\ifdim \dimen1<2\baselineskip
\vfil\break \dimen1=\vsize \corrsize{\dimen1} \fi
\ifnum\mullines<\tmpnum \dimen0=\ht6 \else \dimen0=.8\maxdimen \fi
\divide\dimen0 by\Ncols \relax
%% split the material to more pages?
\ifdim \dimen0>\dimen1 \splitpart
\else \balancecolumns \fi % only balancing
\egroup
}
\def\makecolumns{\bgroup % full page, destination height: \dimen1
\vbadness=20000 \setbox1=\hbox{}\tmpnum=0
\loop \ifnum\Ncols>\tmpnum
\advance\tmpnum by1
\setbox1=\hbox{\unhbox1 \vsplit6 to\dimen1 \hss}
\repeat
\hbox{}\nobreak\vskip-\splittopskip \nointerlineskip
\null\nobreak\medskip\hbox to\hsize{\unhbox1\unskip}
\dimen0=\dimen1 \divide\dimen0 by\baselineskip \multiply\dimen0 by\Ncols
\global\advance\mullines by-\dimen0
\egroup
}
\def\splitpart{%
\makecolumns % full page
\vskip 0pt plus 1fil minus\baselineskip \break
\ifnum\mullines<\tmpnum \dimen0=\ht6 \else \dimen0=.8\maxdimen \fi
\divide\dimen0 by\Ncols \relax
\ifx\balancecolumns\flushcolumns \advance\dimen0 by-.5\vsize \fi
\dimen1=\vsize \corrsize{\dimen1}\dimen2=\dimen1
\advance\dimen2 by-\Ncols\baselineskip
%% split the material to more pages?
\ifvoid6 \else
\ifdim \dimen0>\dimen2 \expandafter\expandafter\expandafter \splitpart
\else \balancecolumns % last balancing
\fi \fi
}
\def\balancecolumns{\bgroup \setbox7=\copy6 % destination height: \dimen0
\ifdim\dimen0>\baselineskip \else \dimen0=\baselineskip \fi
\vbadness=20000
\def\tmp{%
\setbox1=\hbox{}\tmpnum=0
\loop \ifnum\Ncols>\tmpnum
\advance\tmpnum by1
\setbox1=\hbox{\unhbox1
\ifvoid6 \hbox to\wd6{\hss}\else \vsplit6 to\dimen0 \fi\hss}
\repeat
\ifvoid6 \else
\advance \dimen0 by.2\baselineskip
\setbox6=\copy7
\expandafter \tmp \fi}\tmp
\hbox{}\nobreak\vskip-\splittopskip \nointerlineskip
\null\nobreak\medskip\hbox to\hsize{\unhbox1\unskip}%
\egroup
}
\begin{document}
\chapter{Example}
\lipsum[1-9]
\begmulti 2
\lipsum[1-4]
\endmulti
\end{document}
答案1
请注意,和\begmulti
在\endmulti
纯 TeX 中没有问题。我不知道为什么 LaTeX 在这种情况下不起作用,但我不会深入研究它,因为 LaTeX 不是我的首要任务。可以有一个补丁(也许它会在更多情况下起作用:):
\advance\dimen1 by-\baselineskip
尝试在代码第 29 行后添加,即:
\ifdim\pagegoal=\maxdimen \dimen1=\vsize \corrsize{\dimen1}
\else \dimen1=\pagegoal \advance\dimen1 by-\pagetotal \fi
\advance\dimen1 by-\baselineskip % <<< this line is added
\ifdim \dimen1<2\baselineskip
...