Exercise 1: Loading and Displaying Data (Solution)
This is a solution to Exercise 1. You need the sample files booklist.csv and country-codes.csv. Alternatively, if you want to use data from the samples SQL database, remember to use datatooltk to import the data to a .dbtex file and load it using \DTLloaddbtex as described in Loading Data From a .dbtex File.Note that two LaTeX runs are required for the longtable to correctly align the table columns. This is a feature of the longtable package. (Two LaTeX runs are also required to get the cross-references up-to-date.)
% arara: pdflatex % arara: pdflatex \documentclass[captions=tableabove]{scrartcl} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{datatool} \usepackage{longtable} \usepackage{booktabs} % Load data from booklist.csv: \DTLloaddb{books}{booklist.csv} % Load data from country-codes.csv: \DTLloaddb{countries}{country-codes.csv} % Add rules from booktabs package: \renewcommand{\dtldisplaystarttab}{\toprule}% \renewcommand{\dtldisplayendtab}{\\\bottomrule}% \renewcommand{\dtldisplayafterhead}{\midrule}% \begin{document} The book titles are shown in Table~\ref{tab:books}. \begin{table} \caption{Books} \label{tab:books} \centering \DTLdisplaydb{books} \end{table} The country codes are shown in Table~\ref{tab:countries}. % Make sure you load at least v2.21 of datatool % for the rules to show correctly as earlier versions % had a bug. \DTLdisplaylongdb [% caption={Country Codes},% main caption contcaption={Country Codes (Continued)},% continuation caption label={tab:countries},% label foot={\bottomrule\multicolumn{2}{r}{\emph{Continued on next page}}},% table footer lastfoot={}% final table footer ] {countries} \end{document}
Download dtldisplay.tex or dtldisplay.pdf.