You can use table head
as done by egreg with some more additions:
\csvautolongtable[
table head=\caption{some table}\label{tab:some}\\\hline
\csvlinetotablerow\\\hline
\endfirsthead\hline
\csvlinetotablerow\\\hline
\endhead\hline
\endfoot,
respect all
]{chemicaltable.csv}
Full code:
\documentclass[pdftex,a4paper]{scrartcl}
\usepackage[german, english]{babel}
\usepackage{booktabs}
\usepackage{csvsimple}
\usepackage{caption}
\usepackage{longtable}
\usepackage{filecontents}
\begin{filecontents*}{chemicaltable.csv}
Known effect,Group
microcystin; DNA damage,A
reactive,A
reactive,A
reactive,A
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
Estrogenic,B
anticancer,C
anticancer,C
anticancer,C
antirheumaticum,C
calcium pathway,C
gsk inhibitor,C
Antiandrogen,D
Antiandrogen,D
Antiandrogen,D
Antiandrogen,D
sterol pathway,E
sterol pathway,E
antirheumaticum,F
cyclooxygenase,F
low tox; antiinflammatory,F
endogenous,F
Antibiotic,G
\end{filecontents*}
\setlength{\textheight}{7cm}
\begin{document}
%?\caption{There should be a caption somehow}
%?\label{and a label...}
\csvautolongtable[
table head=\caption{some table}\label{tab:some}\\\hline
\csvlinetotablerow\\\hline
\endfirsthead\hline
\csvlinetotablerow\\\hline
\endhead\hline
\endfoot,
respect all
]{chemicaltable.csv}
Here is my table~\ref{tab:some}
\end{document}
I'm back and I found a partial solution to my problem.
Please keep in mind that I am almost a complete beginner so I'm experimenting. ^^'
(I'm using Overleaf to write my code because I tried on RStudio but the datatool package was apparently not available for R version 3.5.1)
So to simplify, this is the pattern I used:
% Load CSV database (here database.csv)
% and give it a label (here DB)
\DTLloaddb{DB}{database.csv}
%%%%%%%%%%%%%%%%
% Iteration
% Here in the D column I can have d1, d2, etc.
% but I only want to display the result for the rows with d1:
\DTLforeach*[\DTLiseq{\D}{d1}] % Condition
{DB} % Database label
{\A=A,\B=B,\C=C,\D=D,\E=E} % Assignment
{% Stuff to do at each iteration:
\item[]
\textbf{\A}
\textbf{ \B}
\textit{ \C}
(\E)
}
%%%%%%%%%%%%%%%%
In my particular situation, I am doing a wine list/menu (Carte des Vins) and eventually I want to:
1) sort them by wine (Bordeaux / Burgundy / Port / Rest of the World)
For now I'm using a csv file with only the Bordeaux wines (bordeaux.csv) but ultimately I would like to use a file with all the wines on it (wine.csv)
2) sort them by type (Red / White / Sweet white)
As you will see below, I managed to do that, but maybe there is a better way to do the same thing.
3) format the text as follows:
Vintage Name, Classification (Origin)
ex: 2009 Château Grand Village, Bordeaux Supérieur (Bordeaux)
The only thing that I have trouble with is the comma, because when the Classification column is empty I don't want to get "Vintage Name," with a useless comma... So for now I left the text without a comma.
So this is my whole code:
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
% Pour modifer les marges
\usepackage{geometry}
% Marges du document
\geometry{hmargin=2.5cm,vmargin=1.5cm}
% To remove the heading of the table of contents ("Contents")
\makeatletter
\renewcommand\tableofcontents{%
\@starttoc{toc}%
}
\makeatother
% To make itemized lists
% This package provides user control over the layout of the three basic list
% environments: enumerate, itemize and description. It supersedes both enumerate
% and mdwlist (providing well-structured replacements for all their funtionality),
% and in addition provides functions to compute the layout of labels, and to
% ‘clone’ the standard environments, to create new environments with counters of
% their own.
\usepackage{enumitem}
% Datatool package to load external files (cdv)
\usepackage{datatool}
\Huge\title{Carte des Vins}
\author{Buck's}
\date{September 2018}
\begin{document}
\maketitle
\tableofcontents
%--------------------------%
\newpage
\section{Bordeaux}
% Load CSV database and give it a name
\DTLloaddb{BOR}{bordeaux.csv}
\subsection{Red}
%%%%%%%%%%%%%%%%
% Iteration
\DTLforeach*[\DTLiseq{\Type}{Red}] % Condition
{BOR} % Database label
{\Vintage=Vintage,\Name=Name,\Classification=Classification,\Type=Type,\Origin=Origin} % Assignment
{% Stuff to do at each iteration:
\item[]
\textbf{\Vintage}
\textbf{ \Name}
\textit{ \Classification}
(\Origin)
}
%%%%%%%%%%%%%%%%
\subsection{White}
%%%%%%%%%%%%%%%%
% Iteration
\DTLforeach*[\DTLiseq{\Type}{White}] % Condition
{BOR} % Database label
{\Vintage=Vintage,\Name=Name,\Classification=Classification,\Type=Type,\Origin=Origin} % Assignment
{% Stuff to do at each iteration:
\item[]
\textbf{\Vintage}
\textbf{ \Name}
\textit{ \Classification}
(\Origin)
}
%%%%%%%%%%%%%%%%
\subsection{Sweet White}
%%%%%%%%%%%%%%%%
% Iteration
\DTLforeach*[\DTLiseq{\Type}{Sweet white}] % Condition
{BOR} % Database label
{\Vintage=Vintage,\Name=Name,\Classification=Classification,\Type=Type,\Origin=Origin} % Assignment
{% Stuff to do at each iteration:
\item[]
\textbf{\Vintage}
\textbf{ \Name}
\textit{ \Classification}
(\Origin)
}
%%%%%%%%%%%%%%%%
%--------------------------%
\newpage
\section{Burgundy}
\subsection{Red}
\subsection{White}
%--------------------------%
\newpage
\section{Rest of the World}
%--------------------------%
\newpage
\section{Port}
%--------------------------------
\end{document}
And this is what I managed to get so far (this is the beginning of my section "Bordeaux" and of my subsection "Red"):
Best Answer
As described in section 2 of the
csvsimple
manual, the\csvreader
macro takes three mandatory arguments, while you've just added one. That is, the general format iswhile you've just used
(The
\csvautotabular
macro on the other hand, as seen in Abo Ammar's answer has just one mandatory argument, the file name.)The arguments:
The first mandatory argument is the filename of the
.csv
file.The second argument assigns macros to the content of the various columns. For example, if you had a
.csv
file that looked likethen you would use
in the second mandatory argument, to define the two macros
\foo
and\bar
, referring to thea
andb
columns respectively.The third argument is where you define the format of your table rows, using the macros defined in the second argument. For example
to print the
b
column first, anda
column second.\csvreader
also has an optional argument, where you define the column types of your table (e.g.tabular=cc
for two centred columns), and any other formatting you need.A complete example below, using some bits from the example in section 3.4 of the manual. To remove the quotation marks (
"
) from the first column output, I load thexstring
package and use\StrDel{\name}{"}
instead of\name
in the row format. That will delete all occurrences of"
.