# Balancing long table inside multicol in LaTeX

I would like to put some longer tabular data inside the multicols environment while maintaining its balancing abilities. I have tried supertabular with the trick to redefine \newpage as columnbreak. This isn't good though, because the columns aren't properly balanced. Finally I ended up using \halign:

\documentclass[11pt, a4paper]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{supertabular}
\usepackage{multicol}

\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\tablines{\tabline\tabline\tabline\tabline\tabline}
\def\mybreak{\hrule width \columnwidth height 0pt \columnbreak}

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

% % This doesn't balance the columns. Whole table ends up in the left column (it fits)
% \begingroup\let\newpage\mybreak
% \noindent\begin{supertabular*}{\columnwidth}{@{\indent}l l l}
% \tablines\tablines\tablines\tablines\tablines\tablines
% \end{supertabular*}
% \endgroup

\begingroup\let\\\cr
\tablines\tablines\tablines\tablines\tablines\tablines}
\endgroup

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

I was wondering if I'm the only one using \halign to achieve this result. On the other hand supertabular leaves me with an undesired almost empty right column. How would you approach this problem?

-

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.

\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\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}
-
I would never suspect this to work! I may even overlook the runaway vrule at the second "Lorem". :) If longtable works then maybe longtabu will work as well. Still, it's good to see a familiar table environment and not have to dive into hrule texnicalities. :) –  Frg Feb 27 '12 at 16:02
I mean "\halign". And as for the odd extra vrule, I don't get it in my pdf, so it must have been some dead pixels in the screenshot. –  Frg Feb 27 '12 at 16:11
It really does work across multiple pages with both plain longtable and longtabu. Only things like \endhead, \endfoot, \endlastfoot don't appear at all. –  Frg Feb 27 '12 at 16:33
the only thing LT could do with the *head and *foot commands is put either head or firsthead at the start and and either foot or lastfoot at the end, no chance of it doing anything at the break. So really no point in doing anything at all (as you can just put the lines in the table body) but it might be kinder to support that, as it makes it easier to move existing longtables into this useage, –  David Carlisle Feb 27 '12 at 16:36
I kindly ask for Frank and you (or someone else from the LaTeX3 team) to spend some time together again to fix this for LaTeX3: I want true mini pages in multicolumn mode, i.e. columns with separate headers and footers. And of course balanced (or not, if I want). The last time I looked at this the best option for this was to use pdfpages. I'm quite sure that this has been possible with ConTeXt for years, though. –  Martin Schröder Feb 27 '12 at 22:23

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}