Nandan Joshi
Nandan Joshi
2 min read

Categories

Tags

I have been away for long time, since I was busy with my research and presently I’m writing my thesis to the end. Well, I’m working on large number of stellar objects and, of course, I have to provide basic information about them in tabular form at the end of the thesis. So I needed not a simple tabular form usually used in LaTeX, but I have to use another package to make it seamless over many pages. And I think longtable package is perfect for it. Here I tell you how to do it.

So first you have to add this package in preamble of your document:

\usepackage{longtable}

And, then, you can add the following template for longtable wherever you want to add the table:

\begin{center}
% add \scriptsize , if the default font is too big to float the table within boundaries
\begin{longtable}{ l c r r }
%Here is the caption, the entry inside [] is the table of contents entry,
%the entry inside {} is the title that will appear on the first page of the
%table.
\caption[Table of something]{Table of something and more} \label{tab:table_label} \\

%This is the header for the first page of the table...
\hline \hline \\[-2ex]
\multicolumn{1}{l}{Column 1} &
\multicolumn{1}{c}{Column 2} &
\multicolumn{1}{c}{Column 3} &
\multicolumn{1}{c}{Column 4} \\[0.5ex] \hline
\\[-1.8ex] % for better-looking spacing
\endfirsthead % end of the header on first page of the table

%This is the header for the remaining page(s) of the table...
\multicolumn{4}{c}{ {\tablename} \thetable{} -- Continued } \\[0.5ex]
\hline \hline \\[-2ex]
\multicolumn{1}{l}{Column 1} &
\multicolumn{1}{c}{Column 2} &
\multicolumn{1}{c}{Column 3} &
\multicolumn{1}{c}{Column 4} \\[0.5ex] \hline
\\[-1.8ex] % you can change this later part for the table should look different on subsequent pages
\endhead % End of header for remaining pages

%This is the footer for all pages except the last page of the table...
\\[-1.3ex] % Specify any spacing you prefer for the footer
\multicolumn{7}{l}{ {Continued on Next Page\ldots} } \\
\endfoot % End of footer for all but last pages of the table

%This is the footer for the last page of the table...
\\[-1.8ex] \hline \hline
\endlastfoot % End of footer on the last page

% Now the data...
data_c1 & data_c2 & data_c3 & data_c4 \\
data_c1 & data_c2 & data_c3 & data_c4 \\
% more data here
data_c1 & data_c2 & data_c3 & data_c4 \\
data_c1 & data_c2 & data_c3 & data_c4 \\
% data end

\end{longtable}
\end{center}

Please read the accompanying comments and make necessary changes. And that’s all, you have your long table, which spans many pages and looks great.

One more thing: I had a problem with width of the table. I had way too many columns to accomodate within the boundaries. I used \scriptsize to make the fontsize reasonably small. It didn’t help, too. So the best solution is to present the table in landscape mode. Unfortunately, you can’t do that within longtable, but you have to use another package, called landscape. So add the following line in your preamble:

\usepackage{lscape}

And after that, just change the environment from center to landscape in the template above. This solves the problem and you have beautiful table.