\documentclass[thesis_guide.tex]{subfiles}
% chktex-file 1 chktex-file 46

\begin{document}

%==============================================================================
\chapter{Long tables}%
\label{sec:app:tables}
%==============================================================================

\LaTeX\ file: \href{run:./guide_appendix_longtable.tex}{guide\_appendix\_longtable.tex}\\[1ex]
\noindent
Long and complicated tables, such as tables containing the breakdown
of the systematic error for each data point are usually put into the
appendices. Code or data cards can also be included here.
Examples of complicated typesetting have been given already in \cref{G-sec:table}.
In this appendix I give two examples of a table
(\cref{tab:alphabet:xltab,tab:alphabet:longtable}) that goes over more than one page
using the \Package{xltabular} and \Package{longtable} packages.
It is also possible to use the \Package{xtab}  package,
which I also did for a long time.
However, the package seems to have problems with TeX Live 2025,
so I switched to the \Package{xltabular} package,
as \Package{xtab} has not been updated since 2011.
The main use of \Package{xltabular} is that it allows tables with variable width columns
that go over more than one page.

Some features of the \Package{xltabular} package:
\begin{itemize}\setlength{\parskip}{0pt}
  \item You have to terminate the caption (including the label) with \verb|\\|.
  \item It is not possible to include footnotes directly.
    However, you can use the \Package{threeparttablex} package to include notes in a table.
    You should use the environment \Env{ThreePartTable} around the \Env{xltabular} environment
    and define the notes in a \Env{TableNotes} environment before the \Env{xltabular} environment.
    You can then refer to the notes using the \Macro{tnote} macro.
\end{itemize}

Some features of the \Package{longtable} package:
\begin{itemize}\setlength{\parskip}{0pt}
  \item A \Env{longtable} is a combination of \Env{tabular} and \Env{table} in one environment. 
  \item While footnotes do not work properly in a normal \Env{tabular},
    they do work in \Env{longtable}.
  \item You have to terminate the \Macro{caption} (including the label) with \verb|\\|.
  \item If you want the caption to be at the end of the table you should include 
    it in the \Macro{endlastfoot} block.
\end{itemize}

Some features of the \Package{xtab} package:
\begin{itemize}\setlength{\parskip}{0pt}
  \item Use the \Env{mpxtabuar} environment to include footnotes in a table.
  \item You should specify the table header and footer outside the table itself.
  \item Do not include \Env{xtabular} inside a \Env{table} environment, as the table will
    then be output on one page, which is not what you want!
  \item A few things you can tweak to get the page breaks in the right place:
    According to the \Package{xtab} documentation you should first try to play
    around with the variable \Macro{xentrystretch}. The default value is \num{0.1}.
    Decrease this to put more on a page and increase it to get less.
    You can even set it to a negative value!
    The value can be set per table.
    As an alternative you can use the \Macro{shrinkheight} command.
\end{itemize}

As mentioned in \cref{G-sec:package}, an alternative is the \Package{supertabular} package.

\clearpage
The relevant parts of \cref{tab:alphabet:xltab} are:
\begin{tcblisting}{listing only}
\begin{ThreePartTable}
  \begin{TableNotes}
    \item[a] \label{xltab:a} \enquote{a} deserves a footnote.
    \item[b] \label{xltab:b} \enquote{j} deserves a footnote.
  \end{TableNotes}
\begin{xltabular}{\linewidth}{rccX}
  \caption{The alphabet set using the \Package{xltabular} package.}%
  \label{tab:alphabet:xltab0}\\
  \toprule
  \multicolumn{1}{c}{Number} &
  \multicolumn{1}{c}{Letter} &
  \multicolumn{1}{c}{Greek} &
  \multicolumn{1}{c}{Explanation}\\
  \midrule
\endfirsthead
  \midrule
  \multicolumn{1}{c}{Number} &
  \multicolumn{1}{c}{Letter} &
  \multicolumn{1}{c}{Greek} &
  \multicolumn{1}{c}{Explanation}\\
  \midrule
\endhead
  \midrule
  \multicolumn{4}{r}{Continued on next page}\\
  \midrule
\endfoot
  \bottomrule
  \insertTableNotes
\endlastfoot
     1 & a & \(\alpha\) & The lowercase 1st letter in the alphabet\tnote{a}\\
    26 & Z & \(\omega\) & The uppercase 26th letter in the alphabet\\
\end{xltabular}
\end{ThreePartTable}
\end{tcblisting}

\clearpage
The relevant parts of \cref{tab:alphabet:longtable} are:
\begin{tcblisting}{listing only}
\begin{longtable}{rcl}
  \caption{The alphabet set using the \Package{longtable} package.%
  \label{tab:alphabet:longtable0}}\\
  \toprule
  \multicolumn{1}{c}{Number} &
  \multicolumn{1}{c}{Letter} &
  \multicolumn{1}{c}{Explanation}\\
  \midrule
\endfirsthead
  \midrule
  \multicolumn{1}{c}{Number} &
  \multicolumn{1}{c}{Letter} &
  \multicolumn{1}{c}{Explanation}\\
  \midrule
\endhead
  \midrule
  \multicolumn{3}{r}{Continued on next page}\\
  \midrule
\endfoot
  \bottomrule
\endlastfoot
    1 & a & The lowercase 1st letter in the alphabet\footnote{%
    \enquote{a} deserves a footnote}\\
    26 & Z & The uppercase 26th letter in the alphabet\\
\end{longtable}
\end{tcblisting}

\clearpage
The relevant parts for a table using \Env{mpxtabular} are:
\begin{tcblisting}{listing only}
\tablefirsthead{\toprule
  \multicolumn{1}{c}{Number} &
  \multicolumn{1}{c}{Letter} &
  \multicolumn{1}{c}{Greek} &
  \multicolumn{1}{c}{Explanation}\\
  \midrule
}
\tablehead{\midrule
  \multicolumn{1}{c}{Number} &
  \multicolumn{1}{c}{Letter} &
  \multicolumn{1}{c}{Greek} &
  \multicolumn{1}{c}{Explanation}\\
  \midrule
}
\tabletail{\midrule
  \multicolumn{4}{r}{Continued on next page}\\
  \midrule
}
\tablelasttail{\bottomrule}
\bottomcaption{The alphabet set using the \Package{xtab} package.}%
\label{tab:alphabet:xtab0}
\xentrystretch{-0.15}
\begin{center}
  \begin{mpxtabular}{rccl}
     1 & a & \(\alpha\)   & The lowercase 1st letter in the alphabet\footnote{%
       \enquote{a} deserves a footnote}\\
    ...
    26 & Z & \(\omega\) & The uppercase 26th letter in the alphabet\\
  \end{mpxtabular}
\end{center}
\end{tcblisting}

\clearpage
\begin{ThreePartTable}
  \begin{TableNotes}
    \item[a] \label{xxltab:a} \enquote{a} deserves a footnote.
    \item[b] \label{xxltab:b} \enquote{j} deserves a footnote.
  \end{TableNotes}
\begin{xltabular}{\linewidth}{rccX}
  \caption{The alphabet set using the \Package{xltabular} package.
    Greek letters are included using math mode, 
    e.g.\ \texttt{\textbackslash alpha}.}%
  \label{tab:alphabet:xltab}\\
    \multicolumn{1}{c}{Number} &
    \multicolumn{1}{c}{Letter} &
    \multicolumn{1}{c}{Greek} &
    \multicolumn{1}{c}{Explanation}\\
    \midrule
  \endfirsthead
    \midrule
    \multicolumn{1}{c}{Number} &
    \multicolumn{1}{c}{Letter} &
    \multicolumn{1}{c}{Greek} &
    \multicolumn{1}{c}{Explanation}\\
    \midrule
  \endhead
    \midrule
    \multicolumn{4}{r}{Continued on next page}\\
    \midrule
  \endfoot
    \bottomrule
    \insertTableNotes
  \endlastfoot
   1 & a & \(\alpha\)   & The lowercase 1st letter in the alphabet\tnote{a}\\
   2 & b & \(\beta\)    & The lowercase 2nd letter in the alphabet\\
   3 & c & \(\gamma\)   & The lowercase 3rd letter in the alphabet\\
   4 & d & \(\delta\)   & The lowercase 4th letter in the alphabet\\
   5 & e & \(\epsilon\) & The lowercase 5th letter in the alphabet\\
   6 & f & \(\zeta\)    & The lowercase 6th letter in the alphabet\\
   7 & g & \(\eta\)     & The lowercase 7th letter in the alphabet\\
   8 & h & \(\theta\)   & The lowercase 8th letter in the alphabet\\
   9 & i & \(\iota\)    & The lowercase 9th letter in the alphabet\\
  10 & j &              & The lowercase 10th letter in the alphabet\tnote{b}\\
  11 & k & \(\kappa\)   & The lowercase 11th letter in the alphabet\\
  12 & l & \(\lambda\)  & The lowercase 12th letter in the alphabet\\
  13 & m & \(\mu\)      & The lowercase 13th letter in the alphabet\\
  14 & n & \(\nu\)      & The lowercase 14th letter in the alphabet\\
  15 & o & o            & The lowercase 15th letter in the alphabet\\
  16 & p & \(\pi\)      & The lowercase 16th letter in the alphabet\\
  17 & q &              & The lowercase 17th letter in the alphabet\\
  18 & r & \(\rho\)     & The lowercase 18th letter in the alphabet\\
  19 & s & \(\sigma\)   & The lowercase 19th letter in the alphabet\\
  20 & t & \(\tau\)     & The lowercase 20th letter in the alphabet\\
  21 & u & \(\upsilon\) & The lowercase 21st letter in the alphabet\\
  22 & v & \(\phi\)     & The lowercase 22nd letter in the alphabet\\
  23 & w & \(\xi\)      & The lowercase 23rd letter in the alphabet\\
  24 & x & \(\chi\)     & The lowercase 24th letter in the alphabet\\
  25 & y & \(\psi\)     & The lowercase 25th letter in the alphabet\\
  26 & z & \(\omega\)   & The lowercase 26th letter in the alphabet\\
   1 & A & A            & The uppercase 1st letter in the alphabet\\
   2 & B & B            & The uppercase 2nd letter in the alphabet\\
   3 & C & \(\Gamma\)   & The uppercase 3rd letter in the alphabet\\
   4 & D & \(\Delta\)   & The uppercase 4th letter in the alphabet\\
   5 & E & E            & The uppercase 5th letter in the alphabet\\
   6 & F & Z            & The uppercase 6th letter in the alphabet\\
   7 & G & H            & The uppercase 7th letter in the alphabet\\
   8 & H & \(\Theta\)   & The uppercase 8th letter in the alphabet\\
   9 & I & I            & The uppercase 9th letter in the alphabet\\
  10 & J &              & The uppercase 10th letter in the alphabet\\
  11 & K & K            & The uppercase 11th letter in the alphabet\\
  12 & L & \(\Lambda\)  & The uppercase 12th letter in the alphabet\\
  13 & M & M            & The uppercase 13th letter in the alphabet\\
  14 & N & N            & The uppercase 14th letter in the alphabet\\
  15 & O & O            & The uppercase 15th letter in the alphabet\\
  16 & P & \(\Pi\)      & The uppercase 16th letter in the alphabet\\
  17 & Q &              & The uppercase 17th letter in the alphabet\\
  18 & R & P            & The uppercase 18th letter in the alphabet\\
  19 & S & \(\Sigma\)   & The uppercase 19th letter in the alphabet\\
  20 & T & T            & The uppercase 20th letter in the alphabet\\
  21 & U & \(\Upsilon\) & The uppercase 21st letter in the alphabet\\
  22 & V & \(\Phi\)     & The uppercase 22nd letter in the alphabet\\
  23 & W & \(\Xi\)      & The uppercase 23rd letter in the alphabet\\
  24 & X & X            & The uppercase 24th letter in the alphabet\\
  25 & Y & \(\Psi\)     & The uppercase 25th letter in the alphabet\\
  26 & Z & \(\Omega\)   & The uppercase 26th letter in the alphabet\\
\end{xltabular}
\end{ThreePartTable}

\clearpage
\begin{longtable}{rcl}
  \caption{The alphabet set using the \Package{longtable} package.}%
  \label{tab:alphabet:longtable}\\
  \toprule
  \multicolumn{1}{c}{Number} &
  \multicolumn{1}{c}{Letter} &
  \multicolumn{1}{c}{Explanation}\\
  \midrule
\endfirsthead
  \midrule
  \multicolumn{1}{c}{Number} &
  \multicolumn{1}{c}{Letter} &
  \multicolumn{1}{c}{Explanation}\\
  \midrule
\endhead
  \midrule
  \multicolumn{3}{r}{Continued on next page}\\
  \midrule
\endfoot
  \bottomrule
\endlastfoot
   1 & a &  The lowercase 1st letter in the alphabet\footnote{%
               \enquote{a} deserves a footnote}\\
   2 & b & The lowercase 2nd letter in the alphabet\\
   3 & c & The lowercase 3rd letter in the alphabet\\
   4 & d & The lowercase 4th letter in the alphabet\\
   5 & e & The lowercase 5th letter in the alphabet\\
   6 & f & The lowercase 6th letter in the alphabet\\
   7 & g & The lowercase 7th letter in the alphabet\\
   8 & h & The lowercase 8th letter in the alphabet\\
   9 & i & The lowercase 9th letter in the alphabet\\
  10 & j & The lowercase 10th letter in the alphabet\footnote{%
               \enquote{j} deserves another footnote}\\
  11 & k & The lowercase 11th letter in the alphabet\\
  12 & l & The lowercase 12th letter in the alphabet\\
  13 & m & The lowercase 13th letter in the alphabet\\
  14 & n & The lowercase 14th letter in the alphabet\\
  15 & o & The lowercase 15th letter in the alphabet\\
  16 & p & The lowercase 16th letter in the alphabet\\
  17 & q & The lowercase 17th letter in the alphabet\\
  18 & r & The lowercase 18th letter in the alphabet\\
  19 & s & The lowercase 19th letter in the alphabet\\
  20 & t & The lowercase 20th letter in the alphabet\\
  21 & u & The lowercase 21st letter in the alphabet\\
  22 & v & The lowercase 22nd letter in the alphabet\\
  23 & w & The lowercase 23rd letter in the alphabet\\
  24 & x & The lowercase 24th letter in the alphabet\\
  25 & y & The lowercase 25th letter in the alphabet\\
  26 & z & The lowercase 26th letter in the alphabet\\
   1 & A & The uppercase 1st letter in the alphabet\\
   2 & B & The uppercase 2nd letter in the alphabet\\
   3 & C & The uppercase 3rd letter in the alphabet\\
   4 & D & The uppercase 4th letter in the alphabet\\
   5 & E & The uppercase 5th letter in the alphabet\\
   6 & F & The uppercase 6th letter in the alphabet\\
   7 & G & The uppercase 7th letter in the alphabet\\
   8 & H & The uppercase 8th letter in the alphabet\\
   9 & I & The uppercase 9th letter in the alphabet\\
  10 & J & The uppercase 10th letter in the alphabet\\
  11 & K & The uppercase 11th letter in the alphabet\\
  12 & L & The uppercase 12th letter in the alphabet\\
  13 & M & The uppercase 13th letter in the alphabet\\
  14 & N & The uppercase 14th letter in the alphabet\\
  15 & O & The uppercase 15th letter in the alphabet\\
  16 & P & The uppercase 16th letter in the alphabet\\
  17 & Q & The uppercase 17th letter in the alphabet\\
  18 & R & The uppercase 18th letter in the alphabet\\
  19 & S & The uppercase 19th letter in the alphabet\\
  20 & T & The uppercase 20th letter in the alphabet\\
  21 & U & The uppercase 21st letter in the alphabet\\
  22 & V & The uppercase 22nd letter in the alphabet\\
  23 & W & The uppercase 23rd letter in the alphabet\\
  24 & X & The uppercase 24th letter in the alphabet\\
  25 & Y & The uppercase 25th letter in the alphabet\\
  26 & Z & The uppercase 26th letter in the alphabet\\
\end{longtable}

\end{document}
