# Spreading an associative table over several columns

In a paper, I'm using a large amount of associative tables. Tables with a key and value. Since both the keys and values are quite short, this is quite space inefficient.

One could repeat the column headers and thus make more use of a row. For example

H1 H2
A  1
B  2
C  3
D  4

to

H1 H2 H1 H2
A  1  C  3
B  2  D  4

Is their a package to handle such transformations automatically. Doing this manually is quite cumbersome (because the tables are generated by programs) and if it is not always straight forward how much repeats fit on one page...

• Not really an answer, but why not just write a script (e.g. in python) that reads the table as a text file and outputs the latex code as you want it to be? That should be pretty straightforward. – yori Jun 9 '13 at 14:50
• have a look at pgfplotstable – cmhughes Jun 9 '13 at 15:26
• @Yori: I've written such scripts in the past. The problem is that one cannot really measure if a table with n columns will fit on a page. Furthermore it's not really the LaTeX way to worry about layout: the philosophy is that one only writes "the content" of the report and LaTeX being smart enough to figure it out itself. – Willem Van Onsem Jun 9 '13 at 15:49

This could do with a bit more work (it doesn't actually allocate any space for the headings it inserts so you get overfull page warnings and could overprint the footer in principle) but it could be improved, or it might be OK as it is.

It shows a two column table spread over three page columns and two pages.

\documentclass[a5paper]{article}
\usepackage{array,multicol}

\def\a{\stepcounter{enumi}\Roman{enumi}&\theenumi\\}
\def\b{\a\a\a\a\a\a\a\a\a\a\a}
\makeatletter
\let\old@pagesf\page@sofar
\def\page@sofar{%
\process@cols\mult@rightbox{%
\setbox\count@\vbox{\hbox to \columnwidth{%
\old@pagesf}

\makeatother
\begin{document}

\noindent X\dotfill X
\setlength\columnsep{2em}
\begin{multicols}{3}\let\\\cr