0

Lately, I was trying to fit a long multi-column table with a lot of text in a double-column single-file document. The document is making heavy use of single-column tabularxs in two-column mode, my long table is in one-column mode. I struggled in conveniently getting the multi-page table to work with tabularx-like column formatting up to page-width.

As for the convenience/automation part (thanks to the nice overview), I know of

  • tabularx, awesome for column formatting but not for multi-page tables
  • ltablex, awesome for combining tabularx with longtable but not well matching with double-column documents (at least I haven't managed to get around the changes ltablex does to the tabularx package)
  • xtab (enhancement of supertabular), awesome features but without supporting tabularx-style column formatting (at least I haven't managed)
  • tabulary, which nicely automates column formatting but is not the right thing to do multi-page tables

I found some answers on multi-page tables with tabularx (e.g. here, here) and an answer using tabulary (here), not quite doing what I intent.

The following MWE using ltablex does almost what I want:

\documentclass[twocolumn]{article}
\usepackage{lipsum}
% \usepackage{tabularx} % works for 1st table only
\usepackage{ltablex} % works for 2nd table only

\begin{document}
\title{Title}
\author{Author}
\maketitle
\lipsum[1-4]

\begin{table}
  \caption{A small table in twocolumn mode}
  \begin{tabularx}{\columnwidth}{lllXX}
    \textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} & \textbf{C5} \\ 
    A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though. \\
    A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though. 
  \end{tabularx}
\end{table}

\newpage
\onecolumn
\begin{tabularx}{\linewidth}{l>{\hsize.2\hsize}XXX}
  \caption{Full-width multi-page table in one-column mode}\\
  \textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
  \endfirsthead
  \textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
  \endhead
  \multicolumn{4}{r}{{Continued on next page}} \\ 
  \endfoot
  \multicolumn{4}{r}{{End}} \\
  \endlastfoot
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] 
\end{tabularx}

\newpage
\twocolumn
\lipsum[10-14]
\end{document}

The MWE works with either the first table and tabularx or the second table and ltablex. However, with ltablex (which uses longtable), I am getting:

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

Also, I got aware of the ltxtable package, however, it requires a split of files. Can I get ltablex to deal better with twocolumn mode or do I have to switch to ltxtable?

Thank you!

  • You can insert tabularx in a strip environment from the cuted package (sttools bundle). – Bernard Aug 25 '18 at 9:13
  • it isn't clear how you want the page breaking to work, it seems that you do not want the table to be broken at each column, but rather have a full width table with breaking at page rather than column level, in which case the two-column nature of the rest of the document shouldn't be an issue just put \onecolumn before the table and do as you would do for a single column document. that said I think tabularx is over-used and I probably wouldn't use it on a document I was writing by hand in latex (it is more useful for automated production where you have less control over the formatting) – David Carlisle Aug 25 '18 at 10:20
  • @David: Thank you. I am actually talking of a situation where \onecolumn is already in place. I will make this clear in the question. As ltablex came closest to what I wanted but was interfering AND I wanted to keep my other tabularx chunks, I was wondering whether there is a package/a way to do it without this sort of conflict? I read that ltablex has a \setlongtable switch. Believing that this would change ltablex's mode of using longtable and tabularx I tried to set it but couldn't get it to work. – Mario Aug 25 '18 at 10:31
  • Of course, not using tabularx in the first place would be an option. – Mario Aug 25 '18 at 10:34
  • 1
    not really a problem, you could leave all your tabularx, and just change the markup for the multipage table, ltxtable would work for you, or you could use a normal longtable for that table. – David Carlisle Aug 25 '18 at 12:37
1

According to David's suggestion I modified my MWE to be:

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{tabularx} % works for 1st table only
\usepackage{ltxtable} % works for 2nd table only

\begin{document}
\title{Title}
\author{Author}
\maketitle
\lipsum[1-4]

\begin{table}
  \caption{A small table in twocolumn mode}
  \begin{tabularx}{\columnwidth}{lllXX}
    \textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} & \textbf{C5} \\ 
    A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though. \\
    A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though. 
  \end{tabularx}
\end{table}

\newpage
\onecolumn
\LTXtable{\linewidth}{table.tex}

\newpage
\twocolumn
\lipsum[10-14]
\end{document}

with the table in an extra file table.tex:

\begin{longtable}{l>{\hsize.2\hsize}XXX}
  \caption{Full-width multi-page table in one-column mode}\\
  \textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
  \endfirsthead
  \textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
  \endhead
  \multicolumn{4}{r}{{Continued on next page}} \\ 
  \endfoot
  \multicolumn{4}{r}{{End}} \\
  \endlastfoot
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] 
\end{longtable}

This is a decent solution, if we accept to split the document into two files.

0

There is a recent package xltabular making it possible to have all code in a single file, getting rid of interferences of ltablex with (floats in) two-column mode while introducing some convenience over longtable:

\documentclass[twocolumn]{article} 
\usepackage{lipsum}
\usepackage{tabularx} % works for 1st table only
\usepackage{xltabular} % works for 2nd table only

\begin{document}
\title{Title}
\author{Author}
\maketitle
\lipsum[1-4]

\begin{table}
  \caption{A small table in twocolumn mode}
  \begin{tabularx}{\columnwidth}{lllXX}
    \textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} & \textbf{C5} \\ 
    A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though. \\
    A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though. 
  \end{tabularx}
\end{table}

\newpage
\onecolumn
\begin{xltabular}{\linewidth}{l>{\hsize.2\hsize}XXX}
  \caption{Full-width multi-page table in one-column mode}\\
  \textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
  \endfirsthead
  \textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
  \endhead
  \multicolumn{4}{r}{{Continued on next page}} \\ 
  \endfoot
  \multicolumn{4}{r}{{End}} \\
  \endlastfoot
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] \\
  Text & Some other text here & \lipsum[11] & \lipsum[11] 
\end{xltabular}

\newpage
\twocolumn
\lipsum[10-14]
\end{document}

Thanks to David Carlisle for pointing me to that package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.