使用时大卫·卡莱尔的回答(谢谢至在 LaTeX 中平衡多列内的长表\vbox
,当表格前有一些非multicol
文本,并且表格足够长以开始环绕第二列时,我偶然发现了“过满”错误。
代码如下:
\documentclass[11pt, a4paper]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{longtable}
\usepackage{multicol}
\newsavebox\ltmcbox
\def\shortlipsum{\par Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.\par}
\newcounter{entryno}
\setcounter{entryno}{1}
\def\tabline{Test & \the\value{entryno} & Description\addtocounter{entryno}{1}\\}
\def\tablines{\tabline\tabline\tabline\tabline\tabline}
\begin{document}
\shortlipsum
\shortlipsum
\shortlipsum
\shortlipsum
\begin{multicols}{2}
\medskip
\setbox\ltmcbox\vbox{
\makeatletter\col@number\@ne
\begin{longtable}{|l|l|l|}
\tablines\tablines\tablines\tablines\tablines\tablines
\tablines\tablines\tablines\tablines\tablines\tablines
\tablines\tablines\tablines\tablines\tablines\tablines
\tablines\tablines\tablines\tablines\tablines\tablines
\tablines\tablines\tablines\tablines\tablines\tablines
\end{longtable}
\unskip
\unpenalty
\unpenalty
}
\unvbox\ltmcbox
\medskip
\end{multicols}
\shortlipsum
\end{document}
以下是我得到的结果:
理想情况下,我希望表格的第一部分(第一页)正确地换行到第二列,但是,我自己还不够聪明,无法弄清楚这一点。如何做到这一点?
答案1
您可以尝试在 multicol 环境之外设置 longtable:
\documentclass[11pt, a4paper]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{longtable}
\usepackage{multicol}
\newsavebox\ltmcbox
\def\shortlipsum{\par Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.\par}
\newcounter{entryno}
\setcounter{entryno}{1}
\def\tabline{Test & \the\value{entryno} & Description\addtocounter{entryno}{1}\\}
\def\tablines{\tabline\tabline\tabline\tabline\tabline}
\begin{document}
\shortlipsum
\shortlipsum
\shortlipsum
\shortlipsum
\setbox\ltmcbox\vbox{\hsize=\dimexpr 0.5\textwidth-0.5\columnsep\relax%
\begin{longtable}{|l|l|l|}
\tablines\tablines\tablines\tablines\tablines\tablines
\tablines\tablines\tablines\tablines\tablines\tablines
\tablines\tablines\tablines\tablines\tablines\tablines
\tablines\tablines\tablines\tablines\tablines\tablines
\tablines\tablines\tablines\tablines\tablines\tablines
\end{longtable}
\unskip
\unpenalty
\unpenalty
}
\begin{multicols}{2}
\medskip
\unvbox\ltmcbox
\medskip
\end{multicols}
\shortlipsum
\end{document}