# How to have tables automatically create new lines (with header) if they have lots of columns?

I was wondering how to instruct latex to automatically break a table after x columns and create a new line with the same header but with subsequent rows. I attach a picture to make it clearer (I did that manually, I was wondering if that is possible automatically).

First question, sorry for any mistake/not precise content.

I believe your table would become a lot more readable if you transposed it and employed a longtable environment to typeset it.

\documentclass{article}
\usepackage{booktabs,siunitx,longtable}
\usepackage[scr=zapfc]{mathalfa}
\begin{document}
\begin{longtable}{@{}
S[table-format=4.0]
S[table-format=4.0]S[table-format=3.2]
S[table-format=4.0]S[table-format=2.2] @{} }

\toprule
& \multicolumn{2}{c}{\textsc{Cu}}
& \multicolumn{2}{c@{}}{\textsc{Al}}\\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
{Temperature} & {$\varrho$} & {$\mathscr{E}$}
& {$\varrho$} & {$\mathscr{E}$}\\
{[\si{\kelvin}]}  & {[\si{\kilo\gram\per\meter\cubed}]}
& {[$10^9\,\si{\pascal}$]}
& {[\si{\kilo\gram\per\meter\cubed}]}
& {[$10^9\,\si{\pascal}$]}\\
\midrule

\bottomrule
\endfoot

0 & 9028 & 137.0 & & 76.6 \\
10 & 9028 & 137.0 & & 76.59\\
{$\vdots$} & {$\vdots$} & {$\vdots$} & & {$\vdots$}\\
750 & 8718 & 98.30 & & 39.49 \\
{$\vdots$} & {$\vdots$} & {$\vdots$} \\
1250 & 8444 & 61.86 \\
\end{longtable}
\end{document}


I might suggest looking at your "rows" as "vertical columns" in 90deg rotated table with text rotated upright. Maybe using this perspective, you could define an environment that takes your new vertical columns and number "x" (as you described in your question) as parameters. The environment would then have a counter that resets when reaching x and would place a new table each time. Your "header row(s)" would be element (multicol) with your other two "rows". And table name above each table.

I'm pretty new to latex but I'm sure someone could code this approach for you (or come up with a much better solution).

• To be honest I would do this in C++ or any language you are familiar with. Generate latex from a csv file (even let your code do the math and round with correct significant figures if you like). I think that would be the most readable solution (and easy to add/change tables later). – Kris Dec 29 '17 at 5:16