![由于前面的文本,多列中的 longtable 溢出](https://linux22.com/image/453001/%E7%94%B1%E4%BA%8E%E5%89%8D%E9%9D%A2%E7%9A%84%E6%96%87%E6%9C%AC%EF%BC%8C%E5%A4%9A%E5%88%97%E4%B8%AD%E7%9A%84%20longtable%20%E6%BA%A2%E5%87%BA.png)
使用时大卫·卡莱尔的回答(谢谢至在 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}
以下是我得到的结果:
![列不对齐](https://i.stack.imgur.com/wlyih.png)
理想情况下,我希望表格的第一部分(第一页)正确地换行到第二列,但是,我自己还不够聪明,无法弄清楚这一点。如何做到这一点?
答案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}