| 1 |
%% The LaTeX package csvsimple - version 2.7.1 (2026/04/27) |
| 2 |
%% csvsimple-example.tex: an example for csvsimple |
| 3 |
%% |
| 4 |
%% ------------------------------------------------------------------------------------------- |
| 5 |
%% Copyright (c) 2008-2026 by Prof. Dr. Dr. Thomas F. Sturm <thomas dot sturm at unibw dot de> |
| 6 |
%% ------------------------------------------------------------------------------------------- |
| 7 |
%% |
| 8 |
%% This work may be distributed and/or modified under the |
| 9 |
%% conditions of the LaTeX Project Public License, either version 1.3 |
| 10 |
%% of this license or (at your option) any later version. |
| 11 |
%% The latest version of this license is in |
| 12 |
%% http://www.latex-project.org/lppl.txt |
| 13 |
%% and version 1.3 or later is part of all distributions of LaTeX |
| 14 |
%% version 2005/12/01 or later. |
| 15 |
%% |
| 16 |
%% This work has the LPPL maintenance status `author-maintained'. |
| 17 |
%% |
| 18 |
%% This work consists of all files listed in README.md |
| 19 |
%% |
| 20 |
\documentclass{article} |
| 21 |
\usepackage{ifthen,array,booktabs} |
| 22 |
|
| 23 |
\IfFileExists{csvsimple-doc.cfg}{\input{csvsimple-doc.cfg}}{}% ignore this line |
| 24 |
\providecommand\csvpkgprefix{} % ignore this line |
| 25 |
|
| 26 |
\usepackage{\csvpkgprefix csvsimple-l3}% \usepackage{csvsimple-l3} |
| 27 |
|
| 28 |
\begin{document} |
| 29 |
|
| 30 |
%---------------------------------------------------------- |
| 31 |
\section{Automatic table generation (for testing)} |
| 32 |
|
| 33 |
{\small |
| 34 |
\csvautotabular{csvsimple-example.csv}} |
| 35 |
|
| 36 |
|
| 37 |
%---------------------------------------------------------- |
| 38 |
\section{My first CSV table} |
| 39 |
\csvreader[tabular=|l|l|, |
| 40 |
table head=\hline\multicolumn{2}{|c|}{\bfseries My telephone book}\\\hline |
| 41 |
\bfseries Name & \bfseries Number\\\hline\hline, |
| 42 |
late after line=\\\hline]% |
| 43 |
{csvsimple-example.csv}{last name=\surname,first name=\givenname,telephone=\telephone}{% |
| 44 |
\givenname\ \surname & \telephone |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
%---------------------------------------------------------- |
| 49 |
\section{Remembering the names} |
| 50 |
\csvnames{my names}{last name=\surname,first name=\givenname,address=\address,zip=\zip,telephone=\telephone,year of birth=\birthyear} |
| 51 |
|
| 52 |
\csvreader[my names, late after line=\\, late after last line=]% |
| 53 |
{csvsimple-example.csv}{}{% |
| 54 |
\givenname\ was born in \birthyear\ and lives in \address. |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
%---------------------------------------------------------- |
| 59 |
\section{Filter fun} |
| 60 |
|
| 61 |
\csvreader[my names, filter equal={\address}{Shrimpsbury}, tabbing, |
| 62 |
table head=\bfseries Shrimpsbury friends: \=\hspace*{3cm}\=\+\kill, |
| 63 |
before first line=\<\bfseries Shrimpsbury friends:\>]% |
| 64 |
{csvsimple-example.csv}{}{% |
| 65 |
\surname, \givenname \> \telephone |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
%---------------------------------------------------------- |
| 70 |
\section{More filter fun} |
| 71 |
|
| 72 |
\csvreader[my names, filter ifthen=\birthyear<1980, centered tabular=rllr, |
| 73 |
table head=\multicolumn{4}{c}{\bfseries People born before 1980}\\\toprule |
| 74 |
\# & Name & Postal address & input line no.\\\midrule, |
| 75 |
late after line=\\, late after last line=\\\bottomrule]% |
| 76 |
{csvsimple-example.csv}{}{% |
| 77 |
\thecsvrow & \givenname\ \surname & \zip\ \address & \thecsvinputline |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
%---------------------------------------------------------- |
| 82 |
\section{Again and again} |
| 83 |
|
| 84 |
\csvstyle{my table}{my names, |
| 85 |
centered tabular=|r|l|l|l|, |
| 86 |
table head=\hline\multicolumn{4}{|c|}{\bfseries #1}\\\hline |
| 87 |
\# & Name & Telephone & Postal address\\\hline\hline, |
| 88 |
late after line=\\, late after last line=\\\hline} |
| 89 |
|
| 90 |
\csvreader[my table=Predefined table]{csvsimple-example.csv}{}{% |
| 91 |
\thecsvrow & \givenname\ \surname & \telephone & \zip\ \address |
| 92 |
} |
| 93 |
|
| 94 |
\csvreader[my table=Filtering for Smith, filter equal={\surname}{Smith}]% |
| 95 |
{csvsimple-example.csv}{}{% |
| 96 |
\thecsvrow & \givenname\ \surname & \telephone & \zip\ \address |
| 97 |
} |
| 98 |
|
| 99 |
\csvstyle{all and everything}{my table=#1, file={csvsimple-example.csv}, |
| 100 |
command=\thecsvrow & \givenname\ \surname & \telephone & \zip\ \address} |
| 101 |
|
| 102 |
\csvloop{all and everything=Loop instead of reader} |
| 103 |
|
| 104 |
\csvloop{all and everything=With Shrimpsbury filter, filter equal={\address}{Shrimpsbury}} |
| 105 |
|
| 106 |
\csvloop{all and everything=A little modification, late after line=\\\hline} |
| 107 |
|
| 108 |
|
| 109 |
\end{document} |
| 110 |
|