# Using multiple autogenerated longtables inside multicols environment

I have several longtables which are auto generated. Since they are not actually long or wide ones, it would be rather space saving for me if I could pack them in a multi column environment.

So, I tried something like this.

\documentclass{article}

\usepackage{longtable}

\usepackage{multicol}

\usepackage{filecontents}

\begin{document}

\begin{filecontents}{\jobname autotables.tex}
\begin{longtable}{|l|l|}
1&2\\
3&4
\end{longtable}
\begin{longtable}{|l|l|}
5&6\\
7&8
\end{longtable}
\begin{longtable}{|l|l|}
9&A\\
B&C
\end{longtable}
\begin{longtable}{|l|l|}
D&E\\
F&0
\end{longtable}
\end{filecontents}

\begin{multicols}{4}
\input \jobname autotables.tex
\end{multicols}

\end{document}


But this generates an error message like,

! Package longtable Error: longtable not in 1-column mode.

Indeed, the package documentation says,

longtable now issues an error if started in the scope of \twocolumn, or the multicols environment.

So, looks like I am facing a stumbling block.

However, I am making this post with the hope that somebody could point me to a solution.

Here are the facts and/or bottom lines,

1. The tables are auto generated and anything other than longtable can not be used.
2. The tables are always inside a single file, and the number of tables is not fixed.
3. Post editing the auto generated file is not an option.

UPDATE 1

Tried the code at https://tex.stackexchange.com/a/46001/14103. Unfortunately, the trick works when there is only one longtable inside multicols.

See the following code where the first case works but the second one does not.

\documentclass{article}

\usepackage{longtable}

\usepackage{multicol}

\usepackage{filecontents}

\makeatletter
\newsavebox\ltmcbox
\def\putdbtables#1{\setbox\ltmcbox\vbox{
\makeatletter\col@number\@ne
\input {#1}
\unskip
\unpenalty
\unpenalty}
\unvbox\ltmcbox}
\makeatother

\begin{document}

\begin{filecontents}{\jobname onetables.tex}
\begin{longtable}{|l|l|}
1&2\\
3&4
\end{longtable}
\end{filecontents}

\begin{filecontents}{\jobname twotables.tex}
\begin{longtable}{|l|l|}
1&2\\
3&4
\end{longtable}
\begin{longtable}{|l|l|}
5&6\\
7&8
\end{longtable}
\end{filecontents}

% This will work
\begin{multicols}{4}
\putdbtables{\jobname onetables.tex}
\end{multicols}

% This will generate an error
\begin{multicols}{4}
\putdbtables{\jobname twotables.tex}
\end{multicols}

\end{document}

• longtable doesn't work with multicolumn/twocolumn. Use supertabular instead (I have read the last lines, but unless David does something, it won't work). – user11232 Oct 21 '14 at 8:22
• BTW, there is one question (similar) where David has an answer. I am unable to find it though for now. – user11232 Oct 21 '14 at 8:24
• @HarishKumar I googled thoroughly before asking this question. If you could point me to the one you mentioned, I can propose to close my question, provided that one provides a solution. – Masroor Oct 21 '14 at 8:29
• Gotcha! Balancing long table inside multicol in LaTeX. I think this is the one. But there may be others too. Please don't close yet. Let David come for answer. – user11232 Oct 21 '14 at 8:32
• that link is OK there is (or will be) some experimental longtable v5 code on googlecode (google for it it's not ready yet:-) but for now that answer is what there is. Or you could use supertabular or xtab which work in multicols (but don't take part in the balancing) – David Carlisle Oct 21 '14 at 8:46