I want to include a very long and narrow table in a Latex document. (I am in \documentclass{amsart} if that is relevant.) The table has almost 3000 rows and 3 narrow columns. When I inserted it using the normal tabular environment it spanned almost 80 pages!
Therefore, I would like to insert the table in a multicolumn environment, preferably with 3 columns, in order to save space. I would like the headings of the table to repeat each time the table starts in a new column. I would like to add a caption to the table which repeats on each new page. Finally, I would like the table to sit nicely with the rest of my text (it is part of an essay).
I am not an experienced user of Latex and pieced together some advice from forums online. Below is what I came up with. I would really appreciate some advice on how to improve on the problems I am having with what I have written so far. Alternatively, let me know if you have a better way of going about this.
I found some advice online saying to use the environment xtabular and the multicolumn environment, which I have transferred my table to, but I am having some problems.
- Originally I started the table midpage, after some other text relating to it. This meant that the table only had about 5 rows before it went onto the next column. This was fine for the first page. However, it continued only doing 5 rows in each column on the next new page i.e. not filling up the entire page! As a temporary fix, I added \newpage before the table, so now the table is spanning an entire page, but it means that I have a gap in my document. So, my first problem is getting the table to format nicely with the rest of the text. If it is necessary for the table to start on a newpage, that would be ok. As long as the text after the table filled the gap that it has left.
- My second problem is that the table is exceeding the margins which the rest of the text sits in. It seems to be fine everywhere except the bottom margin, where it is going over the page number and close to the bottom of the page.
- I don't know how to add a caption which repeats on every page that the table is on.
- This is a weird one. Only on the first column of the first page that the table is on, the table is finishing 1 row earlier than the entire rest of it.
This is in the preamble:
Code: Select all
\maxdeadcycles=5000
\makeatletter
\let\mcnewpage\newpage
\newcommand{\changenewpage}{%
\renewcommand\newpage{%
\if@firstcolumn
\hrule width\linewidth height0pt
\columnbreak
\else
\mcnewpage
\fi
}}
\makeatother
Code: Select all
\newpage
\begin{multicols*}{3}
\changenewpage
\tablehead{\toprule
Apple & Banana & Orange \\*}
\begin{xtabular}{
>{\centering\arraybackslash}p{\dimexpr.4\columnwidth-6\tabcolsep}
>{\centering\arraybackslash}p{\dimexpr.5\columnwidth-6\tabcolsep}
>{\centering\arraybackslash}p{\dimexpr.4\columnwidth-6\tabcolsep}}
\midrule
1 & 2 & 3 \\* \midrule
1 & 2 & 3 \\* \midrule
1 & 2 & 3 \\* \midrule
1 & 2 & 3 \\* \midrule
%etc...
1 & 2 & 3 \\* \bottomrule
\label{table:results}
\end{xtabular}
\end{multicols*}