1

Revised Question to Add Clarity

When trying to incorporate a wide (wider than \columnwidth), long table (longtblr) in a twocolumn document class like article, the table will spill onto the next column instead of the next page. How can I overcome this?

Here's an MWE (adapting the longtblr example from Chapter 4 of the tablurarray package (v2023A)):

\documentclass[twocolumn]{article}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\begin{longtblr}[ caption = {A Long Long Long Long Long Long Long Table}, entry = {Short Caption}, label = {tblr:test}, note{a} = {It is the first footnote.}, note{$\dag$} = {It is the second long long long long long long footnote.}, remark{Note} = {Some general note. Some general note. Some general note.}, remark{Source} = {Made up by myself. Made up by myself. Made up by myself.}, ]{ colspec = {lll}, rowhead = 2, rowfoot = 1, row{odd} = {gray9}, row{even} = {brown9}, row{1-2} = {purple7}, row{Z} = {blue7}, } \hline Head & Head & Head \ \hline Head & Head & Head \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta\TblrNote{a} & Eta \ \hline Iota & Kappa\TblrNote{$\dag$} & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Foot & Foot & Foot \ \hline \end{longtblr}

\end{document}

This produces the following output:

Problem with wide, long tables

Original Question

I have a two column (or double column) template where I want to use longtblr for tables. I really like how tabularray (where longtblr is defined) works. It is simple, easy to use, and most of all, it looks quite nice (my subjective opinion). I used it for single column documents and also for two columnm documents with small tables. However, I don't quite get the hang of it for using it properly for wide tables which span accross two columns. Here is an example:

\documentclass[twocolumn]{article}
\usepackage{xcolor}
\usepackage{tabularray}
\NewTblrTheme{TC}{%
\DefTblrTemplate{contfoot-text}{default}{Continued on next column/page}
\SetTblrStyle{contfoot-text}{font=\footnotesize\itshape, fg=black!80}
}
\usepackage{lipsum}

\begin{document} \lipsum[1-2]

\begin{longtblr}[
theme = TC,
caption = {Long table caption.},
label = {table:ips},
]{
    hlines, vlines,
    colspec = { X[l] X[2,l] X[3,l]},
    rowhead = 2,
    %   colsep = 3pt,
    row{even} = {gray9},
    row{1} = {blue!30},
    row{2} = {font=\small\bfseries, c}
}
\SetCell[c=3]{c}        A nice Table
&               &               \\
Part A  &   Part B      &   Part C      \\
Hmmm    & This is not & what I want \\
Hmmm    & This is not & what I want \\
Hmmm    & This is not & what I want \\
Hmmm    & This is not & what I want \\
Hmmm    & This is not & what I want \\
Hmmm    & This is not & what I want \\
Hmmm    & This is not & what I want \\
Hmmm    & This is not & what I want \\
Hmmm    & This is not & what I want \\
Hmmm    & This is not & what I want \\

\end{longtblr} \lipsum[3-4]

\begin{table} \begin{longtblr}[ theme = TC, caption = {Long table caption.}, label = {table:ips}, ]{ hlines, vlines, colspec = { X[l] X[2,l] X[3,l]}, rowhead = 2, % colsep = 3pt, row{even} = {gray9}, row{1} = {blue!30}, row{2} = {font=\small\bfseries, c} } \SetCell[c=3]{c} A nice Table & & \ Part A & Part B & Part C \ With a table around longtblr environment & it seems to work partially & but then it duplicates the table \ With a table* around longtblr environment & it seems to work partially & but then it duplicates the table \

\end{longtblr} \end{table*}

\lipsum[5-12]

\end{document}

Which produces this: Desired Table Explanation

My Question: How can I make this table span two columns? Thank you very much.

If this is not possible, how can I replicate a similar table with another package that works? (Notice the alternating color between rows)

EDIT: Added a minimal example. Thanks to Zarko.

possum
  • 125
  • Please extend your code fragment to complete small document, which reproduce your problem! – Zarko Jan 31 '22 at 13:51
  • 1
    I think you should use a table* environment and put a regular tblr in it. – Pieter van Oostrum Jan 31 '22 at 13:51
  • Thanks for your comment. I tried what you suggested and put a table* around it. However, it duplicates my table (I think it gets duplicated because it would go over the end of a column but I am not sure) – Captain GouLash Jan 31 '22 at 15:47
  • Can I conclude, that you actually not need long table since it can be fit on one page? BTW, it will be nice, that you will mentioned that code is taken from my answer ;-). – Zarko Jan 31 '22 at 17:53

3 Answers3

3

Pure guessing what you after:

\documentclass[twocolumn]{article}
\usepackage{xcolor}
\usepackage{tabularray}
\NewTblrTheme{TC}{%
    \DefTblrTemplate{contfoot-text}{default}{Continued on next column/page}
       \SetTblrStyle{contfoot-text}{font=\footnotesize\itshape, fg=black!80}
                  }
\usepackage{lipsum}

\begin{document} \lipsum[1-2]

\begin{longtblr}[ theme = TC, caption = {Long table caption.}, label = {table:ips}, ]{ hlines, vlines, colspec = { X[l] X[2,l] X[3,l]}, rowhead = 2, % colsep = 3pt, row{even} = {gray9}, row{1} = {blue!30}, row{2} = {font=\small\bfseries, c} } \SetCell[c=3]{c} A nice Table & & \ Part A & Part B & Part C \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ \end{longtblr}

\lipsum[3-4] \end{document}

enter image description here

Edit: It is still unclear what is your problem and how big is your table. From edited question one can conclude, that you not need a long table but you like that it span two columns. Am I right?

If this is the case, than try the following:

\documentclass[twocolumn]{article}
\usepackage{xcolor}
\usepackage{tabularray}

\usepackage{lipsum}

\begin{document} \lipsum[1-5]

\begin{table*}[t]
\caption{Long table caption.}
\label{table:ips}

\begin{tblr}{ hlines, vlines, colspec = { X[l] X[2,l] X[3,l] }, rowhead = 2, row{even} = {gray9}, row{1} = {blue!30}, row{2} = {font=\small\bfseries, c} } \SetCell[c=3]{c} A nice Table & & \ Part A & Part B & Part C \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ Hmmm & This is not & how I want it \ It is & not clear & what you want \ \end{tblr} \end{table*} \lipsum[6-12] \end{document}

enter image description here

Zarko
  • 296,517
  • Thanks for this example! I changed it a bit and used it above for a minimal working example. However, this is not how I want the table., The table should span across the two columns (see updated image in question) – Captain GouLash Jan 31 '22 at 15:45
  • @CaptainGouLash, in accordance with the site policy, consider to award answer by voting it (by clicking on up-triangle at top left side of answer or even to accept it (by clicking on the check mark at the same place). as I see, so far you not accept any of received answers on your questions. – Zarko Jan 31 '22 at 18:12
  • Thanks for your answer. Indeed, in my specific case it should be fine to use tblr instead of longtblr. But once the the table does not fit to the page anymore, it gets somehow duplicated (see in my question the orange marked table is actually duplicated). Is there a way to have the table span over two columns AND have it longer than a page? You can replicate it with your last answer by a) adding more rows (content) to the table and b) change tblr to longtblr – Captain GouLash Jan 31 '22 at 19:58
  • Long tables had not to be enclosed in table float. You need to clarify (in question) what is your problem. – Zarko Jan 31 '22 at 20:49
3

You may use multicol package and put two column text inside multicols environments:

\documentclass{article}

\usepackage{xcolor} \usepackage{tabularray} \usepackage{lipsum} \usepackage{multicol}

\begin{document}

\begin{multicols}{2} \lipsum[1] \end{multicols}

\begin{longtblr}[ caption = {Long Table Caption}, label = {table:ips}, ]{ hlines, vlines, colspec = {X[l]X[2,l]X[3,l]}, rowhead = 2, row{even} = {gray9}, row{1} = {blue8}, cell{1}{1} = {c=3}{c}, } A Nice Table & & \ Part A & Part B & Part C \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ Alpha & Beta & Gamma \ \end{longtblr}

\begin{multicols}{2} \lipsum[2-3] \end{multicols}

\end{document}

enter image description here

L.J.R.
  • 10,932
0

The tabularray package defines the \TblrNewPage macro to resolve to LaTeX's \newpage macro. Because \newpage, in a two-column environment, advances to the next column regardless of whether that column is on the same or the next page, you can renew \TblrNewPage to use \clearpage instead.

\renewcommand{\TblrNewPage}{\clearpage}

This StackExchange answer provides a good explanation of \newpage and \clearpage. Note that if you subsequently need a narrow tabularray longtblr, then you will need to renew \TblrNewPage again to change it back to its default of \newpage.

Here's the updated MWE from the revised question above:

\documentclass[twocolumn]{article}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\renewcommand{\TblrNewPage}{\clearpage} %% <--- Added this line only \begin{longtblr}[ caption = {A Long Long Long Long Long Long Long Table}, entry = {Short Caption}, label = {tblr:test}, note{a} = {It is the first footnote.}, note{$\dag$} = {It is the second long long long long long long footnote.}, remark{Note} = {Some general note. Some general note. Some general note.}, remark{Source} = {Made up by myself. Made up by myself. Made up by myself.}, ]{ colspec = {lll}, rowhead = 2, rowfoot = 1, row{odd} = {gray9}, row{even} = {brown9}, row{1-2} = {purple7}, row{Z} = {blue7}, } \hline Head & Head & Head \ \hline Head & Head & Head \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta\TblrNote{a} & Eta \ \hline Iota & Kappa\TblrNote{$\dag$} & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Alpha Alpha Alpha Alpha & Beta Beta Beta Beta & Gamma Gamma Gamma Gamma \ \hline Epsilon & Zeta & Eta \ \hline Iota & Kappa & Lambda \ \hline Nu & Xi & Omicron \ \hline Rho & Sigma & Tau \ \hline Phi & Chi & Psi \ \hline Foot & Foot & Foot \ \hline \end{longtblr}

\end{document}

...and the resulting document: A wide, long table in a two-column environment that spans both columns

possum
  • 125