# Split the content of a table into 2 columns without doing so in the .tex source

I have some 2-column tabular data which looks like this:

Foo    12
Bar    34
Baz    56
Quux   78
Quuz   910
Corge  1112
Grault 1314


And I want to lay it out in a 2x2 = 4-column table, i.e. to have each table row contain two records, each of which has a name cell and a number cell. This in itself is not a problem:

\begin{tabular}{llll}
Foo    & 12    &
Bar    & 34    \\
Baz    & 56    &
Quux   & 78    \\
Quuz   & 910   &
Corge  & 1112  \\
Grault & 1314  &
{}     & {}    \\
\end{tabular}


... and I can do this with a bit of regular-expression work (although you do need support for multiline regex's, which not all editors have).

The problem is, this will result in a "row major" progression i.e.:

1 2
3 4
5 6
7


the first row will have records 1 and 2, the second row will have 3 and 4 etc. What I want is to have a column-major order:

1 5
2 6
3 7
4


when laid out in LaTeX, but I don't want to rearrange the lines in the .tex file and have to interleave the first and second half of the record set.

Can this be done?

Note: I do want this to be in a proper tabular environment, i.e. I'll want different alignments, adding generated content between columns, rules etc. - I just simplified things for this example.

• – Steven B. Segletes May 23 '18 at 11:36
• @StevenB.Segletes: The first one is about transposing the typeset table dimensions as well - a proper transposition, while what I want is just a reordering of the cells in the same-dimension table. But definitely related. The second one is more closely related, but in my case, I want to preserve pairs of cells - name+number - as horizontal, and not treat all data is uniform. – einpoklum May 23 '18 at 11:51

\documentclass{article}
\usepackage{multicol}
\begin{document}
\begin{multicols}{2}
\obeylines\obeyspaces\raggedcolumns
Foo    12
Bar    34
Baz    56
Quux   78
Quuz   910
Corge  1112
Grault 1314
\end{multicols}

\end{document}


And LaTeX tabbing environment (inside the multicols) is better alternative with which you can achieve tabular like alignement with minimal extra mark-up.

\documentclass{article}
\usepackage{multicol}
\begin{document}
\noindent X\dotfill X\par
\begin{multicols}{2}
\begin{tabbing}
XXXXXXXX\=\kill
Foo    \>12   \\
Bar    \>34   \\
Baz    \>56   \\
Quux   \>78   \\
Quuz   \>910  \\
Corge  \>1112 \\
Grault \>1314
\end{tabbing}
\end{multicols}
\noindent X\dotfill X\par
\end{document}


For more info on tabbing, check Lamport's book at your local public library, details in C.10.1. Big advantage is that contrarily to tabular it allows pagebreaks, hence here usage within multicols.

• I didn't actually want the spaces to be taken literally; I'm fine with marking up. Can you modify your answer accordingly? Anyway, +1. – einpoklum May 23 '18 at 9:13
• Use \' for pushing text in a tab delimited column to be right aligned. (although I find usage a bit counterintuitive oh I see the text is flush-right against previous tab stop) – user4686 May 23 '18 at 10:24