I am using the excel to latex add in to generate tables from excel, however, when the table is too long it is not split automatically between 2 (or more pages). Is there any easy way to do this? I have found the longtable package, however, I am not managing to use it with the following code produced by LateX
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}[htbp]
\centering
\caption{Trial}
\begin{tabular}{|r|r|r|r|r}
\cline{1-4} Hello & How & Are & You & \bigstrut\\
\cline{1-4} \multicolumn{1}{|c|}{\multirow{2}[4]{*}{1}} & 2 & \multicolumn{1}{c|}{\multirow{2}[4]{*}{4}} & \multicolumn{1}{c|}{\multirow{2}[4]{*}{5}} & \bigstrut\\
\cline{2-2} \multicolumn{1}{|c|}{} & 3 & \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{} & \bigstrut\\
\cline{1-4} 6 & 7 & 8 & 9 & \bigstrut\\
\cline{1-4} \multicolumn{1}{r}{} & \multicolumn{1}{r}{} & \multicolumn{1}{r}{} & \multicolumn{1}{r}{} & \bigstrut[t]\\
\multicolumn{1}{r}{} & \multicolumn{1}{r}{} & \multicolumn{1}{r}{} & \multicolumn{1}{r}{} & \\
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
I am using a simple example to not get confused with the code here (this example does not span over 2 pages) but if it did, what changes are necessary?
Best Answer
As you've noted, in order to make LaTeX split a long table across pages, it's necessary to use a
longtable
environment instead of nestedtable
andtabular
environments.The following example first shows the table produced by your code (with the code simplified here and there), followed by the same table produced using a
longtable
environment. The four key differences are:The
longtable
environment takes as its argument the material that would be specified as the argument of thetabular
environment. Do not try to nest alongtable
inside atable
.Insert
\\
(line break directive) after\caption
.Since the table's headers and footers may occur repeatedly, specify the repeated material explicitly. Header and footer material is delimited with instructions named
\endfirsthead
,\endhead
,\endfoot
, and\endlastfoot
.No need to provide a
\centering
instruction; thelongtable
is centered by default.