1

I have a long table of around 50 rows with two columns. As it is quite narrow, I would like to present it in two columns (each column would contain the two columns of the table) with a space between them as shown in the picture (the lines represent the content in the table).

One way to do this can be making a table with 5 columns and manually entering the data where I want it to appear, leaving the middle column empty to generate a space between the two parts. I wonder, however, if there is a way to do it automatically, so that if I add any data it gets automatically placed where it should be. I would also like to be able to add \toprule, \midrule and \bottomrule leaving a space between the two columns.

If it makes any difference, I want this to appear on a page that has text that should not appear in columns.

enter image description here

Here is the sample code containing both the method I described and a regular table:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{multicol}


\begin{document}

\begin{center}
  \begin{longtable}{ l l p{1cm} l l }
    \caption{Caption.}\\
    \toprule
    Column 1 & Column 2 &  & Column 1 & Column 2 \\
    \midrule
    \endfirsthead

    \midrule
    Column 1 & Column 2 &  & Column 1 & Column 2 \\
    \midrule
    \endhead
    
%    \bottomrule
%    \endfoot

      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      data1 & data2 &  & data1 & data2\\
      \bottomrule
  \end{longtable}
\end{center}


\begin{center}
  \begin{longtable}{ l l }
    \caption{Caption.}\\
    
    \toprule
    Column 1 & Column 2 \\
    \midrule
    \endfirsthead

    \midrule
    Column 1 & Column 2 \\
    \midrule
    \endhead
    
%    \bottomrule
%    \endfoot

      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      data1 & data2 \\
      \bottomrule
  \end{longtable}
\end{center}

\end{document}
1
  • 2
    Longtable won't run in columns and is tied too closely to \output to use \vsplit. There are lots of longtable clones out there, so one of them should work in columns. See also tex.stackexchange.com/questions/316767/… Commented Aug 3, 2021 at 0:39

1 Answer 1

1

You can use LaTeX3 Programming Layer to put cells into two columns:


Second Answer

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{caption,float}

\usepackage{tabularray}
\NewTableCommand{\toprule}{\cline[0.08em]{1-2}\cline[0.08em]{4-5}}
\NewTableCommand{\bottomrule}{\cline[0.08em]{1-2}\cline[0.08em]{4-5}}
\NewTableCommand{\midrule}{\cline[0.05em]{1-2}\cline[0.05em]{4-5}}

\ExplSyntaxOn
\NewDocumentEnvironment{mytabular}{+b}
  {
    \seq_set_split:Nnn \l_tmpa_seq { \\ } {#1}
    \int_set:Nn \l_tmpa_int { \int_div_round:nn { \seq_count:N \l_tmpa_seq - 1 } {2} }
    \tl_set:Nn \l_tmpa_tl
      {
        \toprule
        Column 1 & Column 2 & & Column 1 & Column 2 \\
        \midrule
      }
    \int_step_inline:nn { \l_tmpa_int }
      {
        \tl_put_right:Nx \l_tmpa_tl
          {
            \seq_item:Nn \l_tmpa_seq {##1} \exp_not:n{ & & }
            \seq_item:Nn \l_tmpa_seq {##1 + \l_tmpa_int } \exp_not:n{ \\ }
          }
      }    
    \tl_put_right:Nn \l_tmpa_tl
      {
        \bottomrule
      }     
    \begin{tblr}[expand=\l_tmpa_tl]{l l p{1cm} l l}
      \l_tmpa_tl
    \end{tblr}
  } { }
\ExplSyntaxOff

\begin{document}

Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text

\begin{table}[H]
\centering
\caption{Table Caption}
\begin{mytabular}
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
\end{mytabular}
\end{table}
    
Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text

\end{document}

enter image description here


First Answer

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{caption,float}

\ExplSyntaxOn
\NewDocumentEnvironment{mytabular}{+b}
  {
    \seq_set_split:Nnn \l_tmpa_seq { \\ } {#1}
    \int_set:Nn \l_tmpa_int { \int_div_round:nn { \seq_count:N \l_tmpa_seq - 1 } {2} }
    \begin{tabular}{l l p{1cm} l l}
    \toprule
    Column 1 & Column 2 & & Column 1 & Column 2 \\
    \midrule
    \int_step_inline:nn { \l_tmpa_int }
      {
        \seq_item:Nn \l_tmpa_seq {##1} & & \seq_item:Nn \l_tmpa_seq {##1 + \l_tmpa_int }
        \int_compare:nNnTF {##1} = {\l_tmpa_int} { \\ \bottomrule } { \\ }
      }
    \end{tabular}
  } { }
\ExplSyntaxOff

\begin{document}

Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text

\begin{table}[H]
\centering
\caption{Table Caption}
\begin{mytabular}
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
  data1 & data2 \\
\end{mytabular}
\end{table}
    
Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text

\end{document}

enter image description here

2
  • Thank you, that's similar to what I can create manually, but I would like the rules to respect the blank space in the middle.
    – user248333
    Commented Aug 3, 2021 at 7:46
  • Sorry, I can not see your image in the question, But I have updated the answer and breaks the rules in the middle.
    – L.J.R.
    Commented Aug 3, 2021 at 8:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .