I'm trying to compile a document with the example code for longtable but I get an error saying that longtable is not in 1-column mode. Suggest me the correct way?
8 Answers
longtable doesn't work well with twocolumn. But you can use supertabular. Here is an example:
\documentclass[twocolumn]{article}
\usepackage{supertabular,booktabs}
\usepackage[textheight=10cm]{geometry} %% just for this example.
\begin{document}
\tablefirsthead{\toprule First&\multicolumn{1}{c}{Name} \\ \midrule}
%
\tablehead{%
\multicolumn{2}{c}%
{{\bfseries Continued from previous column}} \\
\toprule
First&\multicolumn{1}{c}{Name}\\ \midrule}
%
\tabletail{%
\midrule \multicolumn{2}{r}{{Continued on next column}} \\ \midrule}
\tablelasttail{%
\\\midrule
\multicolumn{2}{r}{{Concluded}} \\ \bottomrule}
\begin{supertabular}{ll}
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text comes\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text comes here too \\
content & some text\\
content & some text\\
content & some text\\
content & some text
\end{supertabular}%
\end{document}

As suggested by egreg, xtab is another choice. xtab is built on supertabular while avoiding its weaknesses.
\documentclass[twocolumn]{article}
\usepackage{xtab,booktabs}
\usepackage[textheight=10cm]{geometry} %% just for this example.
\begin{document}
\topcaption{This is top caption}
\bottomcaption{This is bottom caption}
\tablecaption{this is table caption}
\tablefirsthead{\toprule First&\multicolumn{1}{c}{Name} \\ \midrule}
%
\tablehead{%
\multicolumn{2}{c}%
{{\bfseries Continued from previous column}} \\
\toprule
First&\multicolumn{1}{c}{Name}\\ \midrule}
%
\tabletail{%
\midrule \multicolumn{2}{r}{{Continued on next column}} \\ \midrule}
\tablelasttail{%
\\\midrule
\multicolumn{2}{r}{{Concluded}} \\ \bottomrule}
\begin{xtabular}{ll}
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text comes\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text\\
content & some text comes here too \\
content & some text\\
content & some text\\
content & some text\\
content & some text
\end{xtabular}%
\end{document}
- 506,678
-
3Or maybe
xtabthat's based onsupertabular, but it's supposed to enhance it. – egreg Feb 20 '14 at 11:23 -
@egreg Could you please tell me how to replace
Continued on next columnwith , for example,continue Table 1where the table number refers to the respective table? – Diaa Jan 22 '18 at 20:24
If you still want to stick to longtable (e.g. because you are generating LaTeX through pandoc) you could redefine the \longtable command.
A possible solution is this one:
\makeatletter
\let\oldlt\longtable
\let\endoldlt\endlongtable
\def\longtable{\@ifnextchar[\longtable@i \longtable@ii}
\def\longtable@i[#1]{\begin{figure}[t]
\onecolumn
\begin{minipage}{0.5\textwidth}
\oldlt[#1]
}
\def\longtable@ii{\begin{figure}[t]
\onecolumn
\begin{minipage}{0.5\textwidth}
\oldlt
}
\def\endlongtable{\endoldlt
\end{minipage}
\twocolumn
\end{figure}}
\makeatother
NB: it works with two columns, which is what you'll find very often in journal article document classes.
To use this fragment with pandoc, you can e.g. use the -H switch which lets you include some additional code before your actual content. Just create a file called preamble.tex and insert the code above. You can then run pandoc -H preamble.tex and the code will automatically be included.
- 351
- 3
- 5
-
1Thanks for this solution! The snippet works when added after the packages are used. – Martin Oct 05 '15 at 08:12
-
1You are a life saver thank you! I also added this line
\setlength{\LTcapwidth}{\linewidth}to the snippet to make the table caption span over the line without exceeding it. – iamaziz Nov 23 '15 at 08:06 -
1How would you modify this to allow a
longtable*environment where the table's width spans both columns (e.g. here)? – Neal Kruis Nov 17 '16 at 17:35 -
Another option, not covered in the previous answers, is to force single column mode along with a \clearpage before your longtable and then reset it to two column mode after. This would look like:
\clearpage
\onecolumn
\begin{longtable}
...
\end{longtable}
\clearpage
\twocolumn
This is potentially more useful than the previous examples as it doesn't require rebuilding much, and has the added bonus of working in platforms like arXiv.
- 1,159
For the benefit of Huan and others: for hellobenallans answer to work you must first include \usepackage{xtab} in your header.
- 131
-
2Thanks for contributing. Normally, comments belong in the comments section, but I think you can't comment with too little reputation. I added a link to your answer in the comments of the answer you commented. – thymaro Jun 05 '20 at 04:02
-
1Thanks @thymaro, it was indeed the case that I didn't have enough reputation to post a proper comment. – Björn Buckwalter Jun 06 '20 at 17:28
I was also stuck trying to use multiple columns with pandoc, and similar to Marco Torchiano's answer I redefined the longtable environment in a preamble, but in my case I redefined it to use the xtabular environment.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Redefine longtable because it doesn't work in multicolumn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\def\longtable{\@ifnextchar[\newlongtable@i \newlongtable@ii}
\def\newlongtable@i[#1]{%
\renewcommand{\endhead}{\ignorespaces}
\xtabular[#1]}
\def\newlongtable@ii{%
\renewcommand{\endhead}{\ignorespaces}
\xtabular}
\def\endlongtable{\endxtabular}
\makeatother
The code above isn't the prettiest, but seems to work all right when I call pandoc using the --include-in-header (or -H) option:
pandoc \
--standalone \
--from=markdown \
--template=pandoc-template.tex \
--include-in-header=pandoc-preamble.tex \
--pdf-engine=xelatex \
-o out.pdf \
in.md
This can produce a pdf which contains tables in a two-column layout, apparently without issue.
- 121
-
2I got a
Error producing PDF. ! Undefined control sequence. \newlongtable@i ...ad }{\ignorespaces } \xtabular [#1] l.138 \begin{longtable}[]– Huan Oct 03 '18 at 14:13 -
An alternative solution with longtblr environment of tabularray package: it can be used in twocolumn documents.
\documentclass[twocolumn]{article}
\usepackage[margin=15mm]{geometry}
\usepackage{tabularray}
\begin{document}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
\begin{longtblr}[
caption = {Long Long Long Tabular},
entry = {Short Caption},
label = {tblr:test},
]{
colspec = {XXX}, hlines,
rowhead = 2, rowfoot = 1,
row{1-2,Z} = {font=\bfseries},
}
Head & Head & Head \
Head & Head & Head \
Alpha & Beta & Gamma \
Epsilon & Zeta & Eta \
Iota & Kappa & Lambda \
Nu & Xi & Omicron \
Rho & Sigma & Tau \
Phi & Chi & Psi \
Alpha & Beta & Gamma \
Epsilon & Zeta & Eta \
Iota & Kappa & Lambda \
Nu & Xi & Omicron \
Rho & Sigma & Tau \
Phi & Chi & Psi \
Alpha & Beta & Gamma \
Epsilon & Zeta & Eta \
Iota & Kappa & Lambda \
Nu & Xi & Omicron \
Rho & Sigma & Tau \
Phi & Chi & Psi \
Alpha & Beta & Gamma \
Epsilon & Zeta & Eta \
Iota & Kappa & Lambda \
Nu & Xi & Omicron \
Rho & Sigma & Tau \
Phi & Chi & Psi \
Alpha & Beta & Gamma \
Epsilon & Zeta & Eta \
Iota & Kappa & Lambda \
Nu & Xi & Omicron \
Rho & Sigma & Tau \
Phi & Chi & Psi \
Alpha & Beta & Gamma \
Epsilon & Zeta & Eta \
Iota & Kappa & Lambda \
Nu & Xi & Omicron \
Rho & Sigma & Tau \
Phi & Chi & Psi \
Alpha & Beta & Gamma \
Epsilon & Zeta & Eta \
Iota & Kappa & Lambda \
Nu & Xi & Omicron \
Rho & Sigma & Tau \
Phi & Chi & Psi \
Foot & Foot & Foot \
\end{longtblr}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
\end{document}
- 10,932
I came across this page looking to fix the issue with pandoc using longtable in twocolumn mode. I had use the supertabular fix above last year and it worked, but with some updates this year it was giving a \noalign error that I could not sort out.
Putting the code below (which replaces longtable with tabular) in the preamble fixed my issues (and I do not actually want multi-page tables, so this is a fine change for me).
\renewenvironment{longtable}{\begin{center}\begin{tabular}}{\end{tabular}\end{center}}
\renewcommand{\endhead}{}
\renewcommand{\toprule}[2]{\hline}
\renewcommand{\midrule}[2]{\hline}
\renewcommand{\bottomrule}[2]{\hline}
When using Marcos Answer with longtable for acronyms, one might change the figures to be displayed "here" ([t]->[h]), and therefore at the \printacronyms command.
\makeatletter
\let\oldlt\longtable
\let\endoldlt\endlongtable
\def\longtable{\@ifnextchar[\longtable@i \longtable@ii}
\def\longtable@i[#1]{\begin{figure}[h]
\onecolumn
\begin{minipage}{0.5\textwidth}
\oldlt[#1]
}
\def\longtable@ii{\begin{figure}[h]
\onecolumn
\begin{minipage}{0.5\textwidth}
\oldlt
}
\def\endlongtable{\endoldlt
\end{minipage}
\twocolumn
\end{figure}}
\makeatother
- 221

supertabularin two column. – Feb 20 '14 at 09:25