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?
[Tex/LaTex] Keep first column on every page of long sideways-table
longtablerotatingtables
Related Solutions
According to the manual of supertabular, declare
\tablehead{<the code you want for the common headings>}
\tablefirsthead{<the code for the first heading>}
\tabletail{<the code for the common bottoms>}
\tablelasttail{<the code for the last table bottom>}
just before starting the supertabular
.
Pay attention: the supertabular
environment and those declarations are to be enclosed in a group (the center
environment, for instance). Otherwise you'll get the same heads and tails in all supertabular
tables until you change the value of them.
You can use the collcell
package to collect the cell of each row and apply the appropriate macro to the column. Below I defined the columns type W
to apply to apply \ibibleverse{Matthew}{#1}
macro, K
column type to apply \ibibleverse{Mark}{#1}
, and the E
column type to apply \ibibleverse{Luke}{#1}
(column names based on the last characters of Matthew
, Mark
, and Luke
.
Code:
\documentclass{standalone}
\usepackage{collcell}
\newcommand{\ibibleverse}[2]{#1-#2}%
\newcommand{\Matthew}[1]{\ibibleverse{Matthew}{#1}}%
\newcommand{\Mark}[1]{\ibibleverse{Mark}{#1}}%
\newcommand{\Luke}[1]{\ibibleverse{Luke}{#1}}%
\newcommand{\MyCommand}[1]{\textcolor{red}{#1}}
\newcolumntype{W}{>{\collectcell\Matthew}{l}<{\endcollectcell}}
\newcolumntype{K}{>{\collectcell\Mark}{l}<{\endcollectcell}}
\newcolumntype{E}{>{\collectcell\Luke}{l}<{\endcollectcell}}
\begin{document}
\begin{tabular}{W K E}
1:1 & 1:1 & 1:1 \\
1:2 & 1:2 & 1:2 \\
1:3 & 1:3 & 1:3 \\
\end{tabular}
\end{document}
If you want to exclude header tows you can use the solution from Tables header row's: how to ignore the column type? to only apply these macros in you are not in a header row.
Code:
\documentclass{standalone}
\usepackage{collcell}
\usepackage{xcolor}%
\usepackage{etoolbox}
\newtoggle{inTableHeader}% Track if still in header of table
\toggletrue{inTableHeader}% Set initial value
\newcommand*{\StartTableHeader}{\global\toggletrue{inTableHeader}}%
\newcommand*{\EndTableHeader}{\global\togglefalse{inTableHeader}}%
% Redefine tabular to initialize \StartTableHeader at start and end
\let\OldTabular\tabular%
\let\OldEndTabular\endtabular%
\renewenvironment{tabular}{\StartTableHeader\OldTabular}{\OldEndTabular\StartTableHeader}%
\newcommand{\ibibleverse}[2]{#1-#2}%
\newcommand{\Matthew}[1]{\iftoggle{inTableHeader}{\textcolor{red}{#1}}{\ibibleverse{Matthew}{#1}}}%
\newcommand{\Mark}[1]{\iftoggle{inTableHeader}{\textcolor{blue}{#1}}{\ibibleverse{Mark}{#1}}}%
\newcommand{\Luke}[1]{\iftoggle{inTableHeader}{\textcolor{brown}{#1}}{\ibibleverse{Luke}{#1}}}%
\newcommand{\MyCommand}[1]{\textcolor{red}{#1}}
\newcolumntype{W}{>{\collectcell\Matthew}{c}<{\endcollectcell}}
\newcolumntype{K}{>{\collectcell\Mark}{c}<{\endcollectcell}}
\newcolumntype{E}{>{\collectcell\Luke}{c}<{\endcollectcell}}
\begin{document}
\begin{tabular}{W K E}
Mathew & Mark & Luke \EndTableHeader\\
1:1 & 1:1 & 1:1 \\
1:2 & 1:2 & 1:2 \\
1:3 & 1:3 & 1:3 \\
\end{tabular}
\end{document}
Best Answer
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: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):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: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.