| 1 |
% This file is public domain. |
| 2 |
\documentclass[captions=tableheading]{scrartcl} |
| 3 |
|
| 4 |
\usepackage{datatool} |
| 5 |
|
| 6 |
\DTLloaddb{scores}{sample-student-records.csv} |
| 7 |
% Sort by surname then first name |
| 8 |
\DTLsort{Surname,First Name}{scores} |
| 9 |
|
| 10 |
\begin{document} |
| 11 |
|
| 12 |
\begin{table}[htbp] |
| 13 |
\caption{Two database rows per tabular row} |
| 14 |
\centering |
| 15 |
\begin{tabular}{llcllc} |
| 16 |
\bfseries First Name & |
| 17 |
\bfseries Surname & |
| 18 |
\bfseries Assignment 1 (\%) & |
| 19 |
\bfseries First Name & |
| 20 |
\bfseries Surname & |
| 21 |
\bfseries Assignment 1 (\%)% |
| 22 |
\DTLforeach*{scores}{\firstname=First Name,\surname=Surname,\score=Assignment 1}{% |
| 23 |
\DTLifoddrow{\\}{&}% |
| 24 |
\firstname & \surname & \score}% |
| 25 |
\end{tabular} |
| 26 |
\end{table} |
| 27 |
|
| 28 |
\begin{table}[htbp] |
| 29 |
\caption{Two database rows per tabular row (column-wise)} |
| 30 |
\centering |
| 31 |
% store half number of rows |
| 32 |
\edef\maxrows{\DTLrowcount{scores}}% |
| 33 |
\DTLdiv{\halfrowidx}{\maxrows}{2} |
| 34 |
\begin{tabular}{llcllc} |
| 35 |
\bfseries First Name & |
| 36 |
\bfseries Surname & |
| 37 |
\bfseries Assignment 1 (\%) & |
| 38 |
\bfseries First Name & |
| 39 |
\bfseries Surname & |
| 40 |
\bfseries Assignment 1 (\%)% |
| 41 |
\DTLforeach*[\value{DTLrowi}<\halfrowidx]{scores}% |
| 42 |
{\firstname=First Name,\surname=Surname,\score=Assignment 1}% |
| 43 |
{% |
| 44 |
\\% |
| 45 |
\firstname & \surname & \score |
| 46 |
& |
| 47 |
\edef\currentrowidx{\arabic{DTLrowi}}% |
| 48 |
\DTLadd{\rowidxII}{\halfrowidx}{\currentrowidx}% |
| 49 |
\DTLassign{scores}{\rowidxII}{\firstnameII=First Name,\surnameII=Surname,\scoreII=Assignment 1}% |
| 50 |
\firstnameII & \surnameII & \scoreII |
| 51 |
}% |
| 52 |
\end{tabular} |
| 53 |
\end{table} |
| 54 |
|
| 55 |
\end{document} |