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,
longtablenow issues an error if started in the scope of\twocolumn, or themulticolsenvironment.
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,
- The tables are auto generated and anything other than
longtablecan not be used. - The tables are always inside a single file, and the number of tables is not fixed.
- 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}

longtabledoesn't work withmulticolumn/twocolumn. Usesupertabularinstead (I have read the last lines, but unless David does something, it won't work). – Oct 21 '14 at 08:22multicolsbut you need the box/unbox on each separately. – David Carlisle Oct 21 '14 at 11:35longtables. Please see the enumerated points at the end of my original post (just above UPDATE 1). – Masroor Oct 21 '14 at 12:07