# Long Tables

### Validation

This page deals with tips related to "uber-huge" tables in psuthesis. Anyway, by "uber-huge" I mean tables that either: (1) cover multiple pages, or (2) cover multiple pages *and* need to be presented landscape.

Courtesy of Ann Hornschemeier we have a style file that allows the use of AAS deluxetables with the psuthesis format, and this works really well, with one exception: uber-huge tables. It doesn't really doesn't work too well because AASTeX is too clever for its own good -- it does not allow you to specify a "table of contents" entry with a deluxetable. So, what happens is LaTeX then takes the title of the deluxetable and adds an individual entry into the table of contents for *each page* that the uber-huge table falls on (which makes for unnecessary clutter). Anyway, I was recently fighting with two uber-huge-landscape tables of my own so I've been stumbling over this for a little while now.

So, I happened across a fix (Google is a wonderful thing), which does not require too much modification from the deluxetable format and is much more friendly to the table of contents by adding only a single entry (but you only need to worry about this if you have tables that span multiple pages, deluxetable works fine for single-page tables -- oh, and you can use this *in addition* to deluxetable).

The fix is to use "longtable" instead of "deluxetable". To do this, you need to add a "\usepackage{longtable}" into the document preamble.

## A basic longtable example

Here is an example of a basic longtable that I found on the web, and modified a little so that the output from it looks very similar to a AASTeX deluxetable (I took out most of the data rows to save space):

\begin{center}
\begin{longtable}{lll}
%the stuff in {} is the title that will appear on the first page of the
%table.
\caption[Feasible triples for a highly variable Grid]{Feasible triples
for highly variable Grid, MLMMH.} \label{grid_mlmmh} \\

%This is the header for the first page of the table...
\hline \hline \\[-2ex]
\multicolumn{1}{c}{\textbf{Time (s)}} &
\multicolumn{1}{c}{\textbf{Triple chosen}} &
\multicolumn{1}{c}{\textbf{Other feasible triples}} \\[0.5ex] \hline
\\[-1.8ex]

%This is the header for the remaining page(s) of the table...
\multicolumn{3}{c}{{\tablename} \thetable{} -- Continued} \\[0.5ex]
\hline \hline \\[-2ex]
\multicolumn{1}{c}{\textbf{Time (s)}} &
\multicolumn{1}{c}{\textbf{Triple chosen}} &
\multicolumn{1}{c}{\textbf{Other feasible triples}} \\[0.5ex] \hline
\\[-1.8ex]

%This is the footer for all pages except the last page of the table...
\multicolumn{3}{l}{{Continued on Next Page\ldots}} \\
\endfoot

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

%Now the data...
0 & (1, 11, 13725) & (1, 12, 10980), (1, 13, 8235), (2, 2, 0), (3, 1, 0) \\
2745 & (1, 12, 10980) & (1, 13, 8235), (2, 2, 0), (2, 3, 0), (3, 1, 0) \\
5490 & (1, 12, 13725) & (2, 2, 2745), (2, 3, 0), (3, 1, 0) \\
8235 & (1, 12, 16470) & (1, 13, 13725), (2, 2, 2745), (2, 3, 0), (3, 1, 0) \\
% <data removed>
164700 & (1, 13, 13725) & (2, 2, 2745), (2, 3, 0), (3, 1, 0) \\
\end{longtable}
\end{center}


Anyway, the biggest differences from a deluxetable are in the headers (you specify headers for the first page, then for each subsequent page separately), and the footers (you can specify a footer for the last page and all other pages).

The longtable example above will produce a multi-page, portrait-oriented table. If you want to make the table oriented landscape, all you need to do is replace the "\begin{center}" and "\end{center}" with "\begin{landscape}" and "\end{landscape}" then add "\usepackage{lscape}" in the preamble (or just add it to: "\usepackage{longtable,lscape}").

## A Note About Table Notes...

I know that some deluxetable commands like "\tablenotemark{}" work in longtable, but some like "\tablenotetext{}{}" do not work (beware, I did not do extensive experimentation with "AASTeX commands"). If you want table notes (similar to what you get from "\tablenotetext{}{}"), then you have to replace all "\tablenotetext{}{}" commands with "\footnotetext[]{}" commands. However, it's not quite that easy, "\footnotetext[]{}" will only take numbers in the [] to use for the footnotes (while "\tablenotemark{}" and "\tablenotetext{}{}" would take numbers, letters, or characters for the footnotes). If you are happy with numbered footnotes, then there is nothing to worry about, just add the appropriate numbers.

If you wanted lettered footnotes, instead of numbered ones in longtable, then you need to take a couple more steps. Before you start your table, you need to issue the command...

     \renewcommand{\thefootnote}{\alph{footnote}}

...then write your table. Enter the "\tablenotemark{}" commands as you normally would with letters, but enter the "\footnotetext[]{}" commands using the number corresponding to the position in the alphabet of the letter you would like as the footnote (a=1, b=2, c=3, ...). Then after your table enter the following to reset the footnotes for the rest of the document...

     \renewcommand{\thefootnote}{\arabic{footnote}}

...or, if you want to use the nine "footnote symbols":

(or in TeX-ese: "$\ast$", "\dag", "\ddag", "\S", "\P", "$\|$", "$\ast\ast$", "\dag\dag", "\ddag\ddag"), then replace "\alph" with "\fnsymbol" in the first "\renewcommand" above. The symbols are accessed by the numbers 1-9 in the "\footnotetext[]{}" command in the order shown above.

## A complicated longtable example

Now here is a complicated example of a landscape formated longtable, with lettered table notes at the end, and script-sized font (again, I removed some of the data to save space):

\begin{landscape}

% Change the footnote style to lowercase letters
\renewcommand{\thefootnote}{\alph{footnote}}

\scriptsize
\begin{center}
\begin{longtable}{llrllrrlcr}
\caption[Equivalent Widths of Dominant Lines in PG~1444+236.]{Equivalent
Widths of Dominant Lines in PG~1444+236.} \label{EWPG1444} \\

\hline \hline \\[-2ex]
\multicolumn{1}{c}{Ion} & \multicolumn{1}{c}{$\lambda$ (\AA)} &
\multicolumn{1}{c}{$\langle\mathrm{EW}\rangle$\tablenotemark{a}} &
\multicolumn{1}{c}{$\sigma$\tablenotemark{b}} &
\multicolumn{1}{c}{S.D.\tablenotemark{c}} &
\multicolumn{1}{c}{Min\tablenotemark{d}} &
\multicolumn{1}{c}{Max\tablenotemark{d}} &
\multicolumn{1}{c}{$\Delta$\tablenotemark{e}} &
\multicolumn{1}{c}{N\tablenotemark{f}} &
\multicolumn{1}{c}{FWHM\tablenotemark{g}} \\[0.5ex] \hline \\[-1.8ex]

\multicolumn{10}{c}{{\tablename} \thetable{} -- Continued} \\[0.5ex]
\hline \hline \\[-2ex]
\multicolumn{1}{c}{Ion} & \multicolumn{1}{c}{$\lambda$ (\AA)} &
\multicolumn{1}{c}{$\langle\mathrm{EW}\rangle$\tablenotemark{a}} &
\multicolumn{1}{c}{$\sigma$\tablenotemark{b}} &
\multicolumn{1}{c}{S.D.\tablenotemark{c}} &
\multicolumn{1}{c}{Min\tablenotemark{d}} &
\multicolumn{1}{c}{Max\tablenotemark{d}} &
\multicolumn{1}{c}{$\Delta$\tablenotemark{e}} &
\multicolumn{1}{c}{N\tablenotemark{f}} &
\multicolumn{1}{c}{FWHM\tablenotemark{g}} \\[0.5ex] \hline \\[-1.8ex]

\multicolumn{10}{l}{{Continued on Next Page\ldots}} \\
\endfoot

\\[-1.8ex] \hline \hline
\endlastfoot

%Data starts here:
H$beta$   & 4861.3 & $-2.98$ & 0.094  & 0.64    &  $-3.43$ & $-2.53$ & 0.90    & 2 &  5.20 \\
He I      & 5875.6 & $0.04$ & 0.057  & 0.033   &  $0.02$ & $0.06$ & 0.04    & 2 &  3.15 \\
H$\alpha$ & 6562.8 & $-104.45$ & 0.24   & 0.29    & $-104.77$ &$-104.23$ & 0.54    & 3 &  6.59 \\
He I      & 6678.1 & $0.11$ & 0.080  & 0.036   &  $0.07$ & $0.14$ & 0.07    & 3 &  3.01 \\
He I      & 7065.2 & $-0.49$ & 0.054  & \nodata & \nodata   & \nodata  & \nodata & 1 &  8.63 \\
H(Pa 22)  & 8359.0 & $-1.24$ & 0.083  & \nodata & \nodata   & \nodata  & \nodata & 1 &  7.81 \\
H(Pa 21)  & 8374.4 & $-1.20$ & 0.078  & \nodata & \nodata   & \nodata  & \nodata & 1 &  8.12 \\
% <data removed>
H(Pa 12)  & 8750.5 & $-9.74$ & 0.15   & \nodata & \nodata   & \nodata  & \nodata & 1 & 10.23 \\
H(Pa 11)  & 8862.8 & $-9.91$ & 0.16   & \nodata & \nodata   & \nodata  & \nodata & 1 & 10.46 \\
% footnote a:
\footnotetext[1]{Average of all EW measurements.}
% footnote b:
\footnotetext[2]{Formal error on the average EW.}
% footnote c:
\footnotetext[3]{Standard deviation of the measurements of the EW.}
% footnote d:
\footnotetext[4]{Minimum/maximum EW value measured.}
% footnote e:
\footnotetext[5]{Difference between the maximum and minimum values measured.}
% footnote f:
\footnotetext[6]{Number of individual measurements.}
% footnote g:
\footnotetext[7]{Average FWHM of the line.}
\end{longtable}
\end{center}
\normalsize

% Reset the footnotes back to numbers
\renewcommand{\thefootnote}{\arabic{footnote}}

\end{landscape}


## Line spacing in longtable

To adjust the spacing between lines in your longtable (i.e., to make the table double or 1.5 spaced for some reason in a single space environment, or to make the table single spaced in a double spaced environment), use the command...

     \renewcommand{\arraystretch}{x.xx}

...where "x.xx" is a line spacing, well, actually it is what the current line spacing is multiplied by before it is applied to the table lines (default is "1"; in single space mode, to double space the table enter "2", for 1.5 spacing enter "1.5", etc.; in double space mode, to single space a table enter "0.5", etc.). I have not done extensive testing of this command, as far as I can tell it will affect all longtables, tabular, and array environments (but not deluxetables) after it is issued (so it might be a good idea to reset it back to "1" after the table if you do not want all tables to have that spacing). You can either specify this command in the preamble of the document (to affect the whole thing), or right before you need it (to affect everything after that point).

## Another fun table trick...

The command "\\" which is used to end a line (in a table or a paragraph), has some special "tricks up-its-sleeve"...

• typing "\\*" will inhibit a page break before the new line (this is especially useful when you have rows of grouped data in a longtable that you don't want broken across two pages).
• typing "\\[len]" or "\\*[len]" (where len is a length, such as 1cm, 1mm, 1in, 1pt, 1ex... either positive or negative) causes extra vertical space the length of len to be added after the line break and before the next line starts. The default is to add no extra space.

## An annoying error, and how to "fix" it

While entering several longtables in a chapter, I encountered a problem where LaTeX basically choked on the last longtable. It continuously said the "table widths have changed, rerun LaTeX", and the table would be formated really crazy no matter how many times I ran LaTeX (normally I found it should take only 3-5 times running LaTeX in order to get the columns of a longtable adjusted appropriately).

The specific circumstances were: I added a new longtable in between two previously existing longtables (so tables 1 and 3 were pre-existing and compiled fine before, and table 2 was the new one). Then, when I compiled the document, LaTeX became unable to format the very last longtable (table 3 -- one of the previously fine tables). So, the "fix" I'm talking about here applies to this last table (the one that was OK, but now with the addition of the new table before it, won't compile anymore).

This problem totally baffled me for a while, but I finally found a "fix" that seemed to work (although I will completely admit that I have absolutely NO idea why this seemed to work). So, if you encounter the problem where LaTeX can't seem to get a longtable formated correctly, here is something you can try (it may, or may not, work for you, and again, I have absolutely NO idea why this worked for me):

1. Copy the offending table into it's own file (remove it from the original chapter file where it is supposed to appear).
2. Add an "\include{}" statement for the file containing the offending table immediately after the "\include{}" statement for the chapter the table is supposed to appear in.
3. Run LaTeX on the whole document (comment out any "\includeonly{}" statements) several times until the "table widths have changed, rerun LaTeX" warning stops appearing at the end of compilation.
4. Copy the offending table back into the original chapter file.
5. Remove the "\include{}" statement for the separate table file.
6. Rerun LaTeX on the whole document several times.
7. Hopefully everything should all be OK now (although I can't explain why).

These files were assembled in Fall 2005 by M. Stark (original files written by Stephen G. Simpson, Math Dept., and are available to download from http://cac.psu.edu/etd/howto/tex/index.html). Some of the files in this tared version were modified from the original versions specifically for Astronomy Dept. use, and others were modified to include new Thesis Office requirements (i.e., inclusion of a "Committee Page" in the eTD in place of a "Signature Page", but keeping the "Signature Page" around to be printed, signed, and turned into the Thesis Office to keep on record).