Balancing long table inside multicol in LaTeX

If you don't want longtable to add headers and footers to the table at the same time that multicol is balancing where to make the break (which would require that frank and I cooperate:-) then multicol will balance the output from longtable if you first trick longtable into thinking that it isn't in multicol at all.

I added some rules, just to show that latex tabular features then work, which is harder to do with a bare \halign.

enter image description here

\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}





\begin{multicols}{2}
\shortlipsum
\medskip

\setbox\ltmcbox\vbox{
\makeatletter\col@number\@ne
\begin{longtable}{|l|l|l|}
\tablines\tablines\tablines\tablines\tablines\tablines
\end{longtable}
\unskip
\unpenalty
\unpenalty}

\unvbox\ltmcbox




\medskip
\shortlipsum
\end{multicols}
\shortlipsum
\end{document}

Package such as longtable and supertabular or, better than the latter, xtab, aim at overcoming a "limitation" of the TeX engine: tabular material has to be entirely read in to find the column widths. For huge tables this may easily lead to memory problems.

Unfortunately, longtable is incompatible with the multicols environment while, as you discovered, supertabular (and xtab) don't maintain the same column width across pages. Using tabular is impossible, as its implementation locks the material into a box and inside \mathon and \mathoff items so it's unbreakable.

For a simple table where you can figure out the column width, you can use tabbing, which splits across pages and columns:

\begin{tabbing}
Test \quad\= 99\quad\=\kill
Test \> \hfil 1  \> Description ... \\
...
Test \> \hfil 30 \> Description ...
\end{tabbing}

For more complex tables I'm afraid that the lower level \halign can be, at the moment, the more flexible solution.


Here’s an environment definition that will allow you to set long tables in multi-column environments (with either the multicols environment or the traditional \twocolumn declarations). It’s also compatible with vanilla longtable but also packages like tabu (for features like growing/shrinking paragraph columns), ltxtable, etc.

Note that some longtable features, like headers and footers at page / column breaks, will be absent, but it mostly works.

\newsavebox\ltmcbox
\newenvironment{fakelongtable}
        {\setbox\ltmcbox\vbox\bgroup
        \csname @twocolumnfalse\endcsname
        \csname col@number\endcsname\csname @ne\endcsname}
        {\unskip\unpenalty\unpenalty\egroup\unvbox\ltmcbox}

Example usage:

\begin{fakelongtable}
    \begin{longtable}{|l|l|l|}
        \tablines\tablines\tablines\tablines\tablines\tablines
    \end{longtable}
\end{fakelongtable}