| 1 |
\documentclass[a4paper]{ltxdoc} |
| 2 |
|
| 3 |
\usepackage[ocgtabular]{ocg-p} |
| 4 |
\usepackage{tikz} |
| 5 |
\usepackage{datatool} |
| 6 |
\usepackage{booktabs} |
| 7 |
|
| 8 |
%\usepackage{array} |
| 9 |
|
| 10 |
\newcommand*{\pkg}[1]{\textsf{#1}} |
| 11 |
|
| 12 |
\title{\pkg{OCG-P} package, example 4} |
| 13 |
|
| 14 |
\begin{document} |
| 15 |
|
| 16 |
% generate database with data for the table |
| 17 |
\DTLnewdb{sdata} |
| 18 |
\DTLnewrow{sdata} |
| 19 |
\DTLnewdbentry{sdata}{Firstname}{John} |
| 20 |
\DTLnewdbentry{sdata}{Lastname}{Doe} |
| 21 |
\DTLnewdbentry{sdata}{Grade}{5} |
| 22 |
\DTLnewrow{sdata} |
| 23 |
\DTLnewdbentry{sdata}{Firstname}{Paul} |
| 24 |
\DTLnewdbentry{sdata}{Lastname}{Bauer} |
| 25 |
\DTLnewdbentry{sdata}{Grade}{1} |
| 26 |
\DTLnewrow{sdata} |
| 27 |
\DTLnewdbentry{sdata}{Firstname}{Peggy} |
| 28 |
\DTLnewdbentry{sdata}{Lastname}{Sue} |
| 29 |
\DTLnewdbentry{sdata}{Grade}{3} |
| 30 |
\DTLnewrow{sdata} |
| 31 |
\DTLnewdbentry{sdata}{Firstname}{Ever} |
| 32 |
\DTLnewdbentry{sdata}{Lastname}{Last} |
| 33 |
\DTLnewdbentry{sdata}{Grade}{4} |
| 34 |
\DTLnewrow{sdata} |
| 35 |
\DTLnewdbentry{sdata}{Firstname}{Werner} |
| 36 |
\DTLnewdbentry{sdata}{Lastname}{Moshammer} |
| 37 |
\DTLnewdbentry{sdata}{Grade}{1} |
| 38 |
|
| 39 |
\maketitle |
| 40 |
|
| 41 |
\section{Without using the ocgtabular environment} |
| 42 |
This table can be sorted by clicking on the headers: |
| 43 |
|
| 44 |
\begin{tikzpicture} |
| 45 |
\begin{ocg}{First Name}{ocfirstid}{1} |
| 46 |
\node[] (p1) { |
| 47 |
\begin{tabular}{llc} |
| 48 |
\toprule |
| 49 |
\bfseries \setocgs{}{ocfirstid}{oclastid ocgradeid}{First name} |
| 50 |
& \bfseries \setocgs{}{oclastid}{ocfirstid ocgradeid}{Last name} |
| 51 |
& \bfseries \setocgs{}{ocgradeid}{ocfirstid oclastid}{Grade} |
| 52 |
\DTLsort*{Firstname}{sdata}% sorted on the first name |
| 53 |
\DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{% |
| 54 |
\DTLiffirstrow{\\ \midrule}{\\} |
| 55 |
\first & \last & \grade |
| 56 |
} |
| 57 |
\\ \bottomrule |
| 58 |
\end{tabular} |
| 59 |
}; |
| 60 |
\end{ocg} |
| 61 |
|
| 62 |
\begin{ocg}{First Name}{oclastid}{0} |
| 63 |
\node[overlay] (p2) { |
| 64 |
\begin{tabular}{llc} |
| 65 |
\toprule |
| 66 |
\bfseries \setocgs{}{ocfirstid}{oclastid ocgradeid}{First name} |
| 67 |
& \bfseries \setocgs{}{oclastid}{ocfirstid ocgradeid}{Last name} |
| 68 |
& \bfseries \setocgs{}{ocgradeid}{ocfirstid oclastid}{Grade} |
| 69 |
\DTLsort*{Lastname}{sdata}% sorted on the last name |
| 70 |
\DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{% |
| 71 |
\DTLiffirstrow{\\ \midrule}{\\} |
| 72 |
\first & \last & \grade |
| 73 |
} |
| 74 |
\\ \bottomrule |
| 75 |
\end{tabular} |
| 76 |
}; |
| 77 |
\end{ocg} |
| 78 |
|
| 79 |
\begin{ocg}{First Name}{ocgradeid}{0} |
| 80 |
\node[overlay] (p3) { |
| 81 |
\begin{tabular}{llc} |
| 82 |
\toprule |
| 83 |
\bfseries \setocgs{}{ocfirstid}{oclastid ocgradeid}{First name} |
| 84 |
& \bfseries \setocgs{}{oclastid}{ocfirstid ocgradeid}{Last name} |
| 85 |
& \bfseries \setocgs{}{ocgradeid}{ocfirstid oclastid}{Grade} |
| 86 |
\DTLsort*{Grade}{sdata}% sorted on the grade |
| 87 |
\DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{% |
| 88 |
\DTLiffirstrow{\\ \midrule}{\\} |
| 89 |
\first & \last & \grade |
| 90 |
} |
| 91 |
\\ \bottomrule |
| 92 |
\end{tabular} |
| 93 |
}; |
| 94 |
\end{ocg} |
| 95 |
|
| 96 |
\end{tikzpicture} |
| 97 |
|
| 98 |
\section{Using the ocgtabular environment} |
| 99 |
|
| 100 |
This table can be sorted by clicking on the headers: |
| 101 |
|
| 102 |
\begin{ocgtabular}{llc}{sdata}{} |
| 103 |
\toprule% |
| 104 |
\bfseries \setocgtabularheader{Firstname}{First name} |
| 105 |
& \bfseries \setocgtabularheader{Lastname}{Last name} |
| 106 |
& \bfseries \setocgtabularheader{Grade}{Grade} |
| 107 |
\DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{% |
| 108 |
\DTLiffirstrow{\\ \midrule}{\\} |
| 109 |
\first & \last & \grade |
| 110 |
} |
| 111 |
\\ \bottomrule% |
| 112 |
\end{ocgtabular} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
\end{document} |