# Keep first column on every page of long sideways-table

I have a table with a lot of columns, so I am going to make it landscape.The very first column is a sort of header, so I would like to repeat it on every page. Is there a way to do that?

-
I think you'd hve to use the longtable package and use \endhead to mark the end of the header that is to appear at the top of the page. –  Peter Grill Jun 2 '12 at 6:58
If your first column is a repeatable header then your table rows presumably repeat in a regular fashion? If you ise for example lscape and longtable you can have a landscape table but the rows split into pages at arbitrary points. If you mean the first row of the table should repeat, then as the first comment noted. \endhead should work. –  David Carlisle Jun 2 '12 at 10:07
Did you mean to say that the first row, rather than the first column, should be repeated on each page? Just checking. –  Mico Jun 2 '12 at 10:52
I think the problem is similar to this one -- a table of one page height, but many columns and therefore several pages width, such that the row identifiers given in the first column should be repeated on every page (@DavidCarlisle, @Mico). –  dgs Jun 8 '12 at 16:28
Depending on your input and the volatility of the data (does this need to work with all kinds of input data or only once?), the easiest thing might be indeed manually splitting the table. Please provide more detail. –  krlmlr Jul 25 '12 at 17:22

I'll try to figure out what the problem is. You have a table with a big number of colums, and presumibly few rows, as for example this one:

You tried rotating it, but still it doesn't fit in one page. So you want to split the table among several pages, and repeat the first column in each page, all of this automatically.

Unfortunately, there is no package which allow you to repeat the first column as a kind of "header". longtable package is the closest, but it only allows the first row to be used as a header (a reasonable choice).

So the first question is, can you transpose your table, converting files into rows and vice-versa? The new big table would look like this (numbers are different because I'm generating them randomly, but this is not important):

First, note that the table is more compact this way, so there are better chances of fitting it into a single page. But even if it is too large, you can leave longtable package to take care of splitting it and repeat the header, using the code provided in other solutions. This will give:

But, if for some reason, you still need that the header is a column instead of a row (I cannot imagine why), then you can use the following dirty trick. Use longtable as in the last example, but rotate 90 degrees each cell. This way the table would look like a "sideways table", and the first row will look like the first column. This is the code:

\documentclass{article}
\usepackage{longtable}
\usepackage{graphicx}
\usepackage{array}
\usepackage{fancybox}
\usepackage[a4paper, margin=3cm]{geometry}

\def\beginrotate{\begin{Sbox}}
\def\endrotate{\end{Sbox}\rotatebox{-90}{\TheSbox~~}}

\begin{document}\footnotesize
\newcolumntype{R}{>{\beginrotate}c<{\endrotate}}
\begin{longtable}{|R|R|R|R|R|R|R|}
\hline
\textbf{Foo} &  \textbf{Bar} &  \textbf{Foobar} & \textbf{Barfoo} &
\textbf{FooFoo} & \textbf{Barbar} & \textbf{Foobaz} \endhead\hline
\input{bigtable}
\\\hline
\end{longtable}
\end{document}


Where bigtable is a file containing the data of a table with 30 rows and 7 colums. Its content is as follows (in order to complete the MWE):

0.6758 & 0.7150 & 0.6982 & 0.3166 & 0.9916 & 0.4469 & 0.6663\\\hline
0.5192 & 0.3351 & 0.1848 & 0.2907 & 0.9938 & 0.9485 & 0.8826\\\hline
0.8872 & 0.9911 & 0.5904 & 0.5111 & 0.8150 & 0.9460 & 0.6106\\\hline
0.6567 & 0.0251 & 0.0072 & 0.2924 & 0.0119 & 0.5548 & 0.8066\\\hline
0.8708 & 0.5457 & 0.6155 & 0.8238 & 0.5979 & 0.5184 & 0.9628\\\hline
0.1505 & 0.3449 & 0.8085 & 0.9886 & 0.5966 & 0.0804 & 0.4170\\\hline
0.6807 & 0.4711 & 0.6918 & 0.4803 & 0.7829 & 0.9600 & 0.1042\\\hline
0.8812 & 0.6242 & 0.7196 & 0.6065 & 0.3812 & 0.0360 & 0.0062\\\hline
0.2533 & 0.4434 & 0.5977 & 0.0679 & 0.7181 & 0.3089 & 0.9971\\\hline
0.3002 & 0.8496 & 0.0992 & 0.5157 & 0.3220 & 0.5868 & 0.9570\\\hline
0.1678 & 0.5196 & 0.6335 & 0.5228 & 0.2306 & 0.8910 & 0.4287\\\hline
0.6802 & 0.5555 & 0.3534 & 0.5206 & 0.1367 & 0.9867 & 0.8026\\\hline
0.7301 & 0.8947 & 0.5710 & 0.0133 & 0.4933 & 0.9754 & 0.1996\\\hline
0.8284 & 0.7035 & 0.3541 & 0.5774 & 0.4192 & 0.4091 & 0.5287\\\hline
0.9641 & 0.2976 & 0.2910 & 0.7979 & 0.5771 & 0.6541 & 0.8497\\\hline
0.2666 & 0.6168 & 0.4662 & 0.2921 & 0.4760 & 0.3647 & 0.8961\\\hline
0.4583 & 0.9469 & 0.4631 & 0.3696 & 0.5438 & 0.9070 & 0.4259\\\hline
0.4572 & 0.6667 & 0.5216 & 0.4976 & 0.2914 & 0.7089 & 0.0738\\\hline
0.6888 & 0.5940 & 0.8692 & 0.0071 & 0.5753 & 0.3133 & 0.4880\\\hline
0.6797 & 0.4619 & 0.3415 & 0.8531 & 0.6565 & 0.4343 & 0.3206\\\hline
0.2041 & 0.6366 & 0.5736 & 0.5109 & 0.6069 & 0.3847 & 0.0896\\\hline
0.8915 & 0.4274 & 0.3350 & 0.4032 & 0.4010 & 0.9764 & 0.7961\\\hline
0.0209 & 0.7044 & 0.5719 & 0.9619 & 0.5674 & 0.2458 & 0.5487\\\hline
0.7091 & 0.8960 & 0.1819 & 0.4002 & 0.4607 & 0.3069 & 0.5067\\\hline
0.1857 & 0.8420 & 0.7223 & 0.7178 & 0.6437 & 0.7449 & 0.6483\\\hline
0.4034 & 0.9813 & 0.0288 & 0.6326 & 0.7765 & 0.6866 & 0.5010\\\hline
0.3131 & 0.3296 & 0.6957 & 0.9979 & 0.3438 & 0.6381 & 0.6289\\\hline
0.7243 & 0.0523 & 0.7895 & 0.7588 & 0.3630 & 0.3918 & 0.9185\\\hline
0.7184 & 0.6831 & 0.5795 & 0.8660 & 0.2125 & 0.3705 & 0.5142\\\hline
0.9295 & 0.6789 & 0.8640 & 0.6584 & 0.1385 & 0.8579 & 0.1618


And the result:

UPDATE

Another crazy idea. You can enclose my last proposed solution into a landscape environment, and thus the table is rotated again 90 degrees counter-clockwise, and it looks portrait, with the effect of the first column being repeated in each page:

\documentclass{article}
\usepackage{longtable,lscape}
\usepackage{graphicx}
\usepackage{array}
\usepackage{fancybox}
\usepackage[a4paper, margin=3cm]{geometry}

\def\beginrotate{\begin{Sbox}}
\def\endrotate{\end{Sbox}\rotatebox{-90}{\TheSbox~~}}

\begin{document}\footnotesize
\newcolumntype{R}{>{\beginrotate}c<{\endrotate}}
\begin{landscape}
\begin{longtable}{|R|R|R|R|R|R|R|}
\hline
\textbf{Foo} &  \textbf{Bar} &  \textbf{Foobar} & \textbf{Barfoo} &
\textbf{FooFoo} & \textbf{Barbar} & \textbf{Foobaz} \endhead\hline
\input{bigtable}
\\\hline
\end{longtable}
\end{landscape}
\end{document}


Resulting in three pages. The result is like cutting the table at the top of this answer into three chunks, and having the first column repeated at each chunk.

-
That's really cool, thanks for this crazyness :) –  jeje Aug 7 '12 at 11:28

Assuming you did mean the first row to be repeated:

  \usepackage{lscape,longtable}


.....

\begin{landscape}
\begin{longtable}{cccc}
....
\end{longtable}
\end{landscape}

-
@egreg, it is now:-) –  David Carlisle Jun 2 '12 at 17:17
No, I mean first coloumn, not first row. And yes, I want the same as \endhead in a normally oriented table. Just imagine it in a transposed way. –  Jelena-bioinf Jun 3 '12 at 13:53
I think you do want the first row repeated. (but in landscape orientation) which is what the above code would produce. If you do not want that you will need to provide a MWE that demonstrates what you do want. the first column will stretch the full length of the table so there is no way it can be "repeated". Unless it is a highly regular table where for example every other row needs the same first entry so you just give the first two and repeat them. –  David Carlisle Jun 3 '12 at 15:58

Unfortunately, there is no much information in your question. An example would have been useful. Anyway, my approach is below. Let us know why it wouldn't work.

\documentclass{amsart}
\usepackage{etoolbox}

\newcounter{hcCounter}[page]
\newcommand{\hcStart}{\stepcounter{hcCounter}\ifnumequal{\value{hcCounter}}{1}{Uno}{\ifnumequal{\value{hcCounter}}{2}{Dos}{\arabic{hcCounter}}}&}

\begin{document}

\begin{tabular}{ l c r }
\hcStart 2 & 3 \\
\hcStart 5 & 6 \\
\hcStart 8 & 9 \\
\hcStart 11 & 12 \\
\end{tabular}

\newpage

\begin{tabular}{ l c r }
\hcStart a & b \\
\hcStart c & d \\
\hcStart e & f \\
\end{tabular}

-