# Proper tables with multicols

Is there a way to tell multicol to leave space at the top of the cols > 1?

The main gotcha is that the table data will be shared and I don't want to chop it up for different places but have the compiler figure it out.

\documentclass{article}
\usepackage{multicol}
\usepackage{longtable}

\newsavebox\ltmcbox

\newcounter{entryno}
\setcounter{entryno}{1}

\begin{document}

\section*{I want this:}
\begin{multicols}{2}
\setbox\ltmcbox\vbox{
\makeatletter\col@number\@ne
\begin{longtable}{ll}
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
Data
& Data\\
{}
& {}\\
Data
& Data\\
Data
& Data\\
\end{longtable}
\unskip
\unpenalty
\unpenalty
}\unvbox\ltmcbox
\end{multicols}

\section*{Or this:}
\begin{multicols}{2}
\setbox\ltmcbox\vbox{
\makeatletter\col@number\@ne
\begin{longtable}{ll}
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
Data
& Data\\
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
\end{longtable}
\unskip
\unpenalty
\unpenalty
}\unvbox\ltmcbox
\end{multicols}

\section*{Not this:}
\begin{multicols}{2}
\setbox\ltmcbox\vbox{
\makeatletter\col@number\@ne
\begin{longtable}{ll}
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
Data
& Data\\
Data
& Data\\
Data
& Data\\
\end{longtable}
\unskip
\unpenalty
\unpenalty
}\unvbox\ltmcbox
\end{multicols}
\end{document}


• to have that automatic would require the authors of multicol and longtable to talk to each other. We've only known each other for 25 years so not really had time to discuss this yet. – David Carlisle Mar 30 '17 at 20:42
• 25 years is indeed a bit early to discuss topics like this - what about 26 years + 1 year implementation? On a more serious note, I guess this means that there is "no way" at the moment? – Eyenseo Mar 30 '17 at 20:46
• it's trickier than it ought to be. Sorry:-) – David Carlisle Mar 30 '17 at 20:48
• as a workaround I would probably take the heading out of the longtable, then under the \section add a full width tabular with effectively a double column header that sits over all four table columns. if your tabular is p cols of known width that is easy, with l it's a bit harder but you could (perhaps) get the widths out of the longtable data in the aux file. – David Carlisle Mar 30 '17 at 20:51
• you mean \ifnum\col@number=2 ? – David Carlisle Mar 30 '17 at 20:55

With the information form David Carlisle I came up with the following environment and helper command.

This will not break nicely at the end of a page but will behave like a minipage. The environment is used to hide all the nastiness and the command to specify different balance cells depending on the amount of columns.

Here is my workaround:

\documentclass{article}
\usepackage{multicol}
\usepackage{longtable}

%-------------------
% Workaround for multicols containing tables
%
% Sets \myMultiCols to \col@number
%  and \col@number to 1
%-------------------
\makeatletter
\newsavebox\mtcbox
\newenvironment{myTableCols}[1]{%
\begin{multicols}{#1}%
\setbox\mtcbox\vbox\bgroup%
\edef\myMultiCols{\the\col@number}%
\col@number\@ne%
}{%
\unskip%
\unpenalty%
\unpenalty\egroup%
\unvbox\mtcbox%
\end{multicols}%
\vspace*{-.35\baselineskip}% TODO check if needed
}
\makeatother
% This fixes the horrendous layout for
\newcommand{\myBalanceColIfColums}[1]{%
\ifdefined\myMultiCols\ifnum\myMultiCols=#1%
\\%
\fi\fi%
}

\begin{document}
\begin{myTableCols}{2}
\begin{longtable}{ll}
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
\myBalanceColIfColums{3}
Data
& Data\\
\myBalanceColIfColums{2}
Data
& Data\\
\myBalanceColIfColums{3}
Data
& Data\\
\end{longtable}
\end{myTableCols}

\begin{myTableCols}{3}
\begin{longtable}{ll}
Cap a
& Cap b\\\hline
Data
& Data\\
Data
& Data\\
\myBalanceColIfColums{3}
Data
& Data\\
\myBalanceColIfColums{2}
Data
& Data\\
\myBalanceColIfColums{3}
Data
& Data\\
\end{longtable}
\end{myTableCols}
\end{document}