% This is an example document accompanying "LaTeX for Administrative Work"
% See www.dickimaw-books.com/latex/admin/ for the book details,
% including licence.
%
% Arara directives to build this document:
%
% arara: pdflatex
% arara: pdflatex
\documentclass[captions=tableheading]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{longtable}
\usepackage{datatool}
\usepackage{booktabs}

\DTLloaddb{countries}{country-codes.csv}

\begin{document}

If the data is too large to fit on a single page we need to use the
\texttt{longtable} environment instead. See Table~\ref{tab:countries}.

\begin{longtable}{cl}
% Set up headers and footers
 \caption{A Sample Long Table}
 \label{tab:countries}\\
 \bfseries Country Code & \bfseries Country Name\\\midrule
 \endfirsthead
 \caption{A Sample Long Table (Continued)}\\
 \bfseries Country Code & \bfseries Country Name\\
 \midrule
 \endhead
 \bottomrule
 \multicolumn{2}{r}{\emph{Continued on next page}}
 \endfoot
 \bottomrule
 \endlastfoot
 \DTLforeach*{countries}{\Code=code,\Name=name}%
 {\DTLiffirstrow{}{\\}\Code & \Name}%
\end{longtable}

\end{document}
