The per-item testing should be performed when setting the item, rather than in the header, since the filter are set globally. From the csvsimple
documentation:
\csvfilterreject
All following data lines will be ignored. This command overwrites all previous filter settings.
\documentclass{article}
\usepackage{csvsimple,filecontents}% http://ctan.org/pkg/{csvsimple,filecontents}
\begin{document}
\begin{filecontents*}{chunk.csv}
AAAA,aaaaa
BBBB,bbbbb
CCCC,ccccc
DDDD,ddddd
EEEE,eeeee
FFFFF,fffffff
GGGGG,ggggg
HHHHHH,hhhhh
\end{filecontents*}
\begin{itemize}
\csvreader[no head]{chunk.csv}{}{\ifnum\value{csvrow}<4\relax\item \csvcoli, \csvcolii\fi}
\end{itemize}
\hrulefill
\begin{itemize}
\csvreader[no head]{chunk.csv}{}{\ifnum\value{csvrow}=4\relax\item \csvcoli, \csvcolii\fi}
\end{itemize}
\hrulefill
\begin{itemize}
\csvreader[no head]{chunk.csv}{}{\ifnum\value{csvrow}>4\relax\item \csvcoli, \csvcolii\fi}
\end{itemize}
\end{document}
Low-level conditionals are used to (not) print each item, testing the value of csvrow
.
Here is an alternative option using datatool
. The interface is very similar, and the transition should therefore not be a problem:
\documentclass{article}
\usepackage{datatool,filecontents}% http://ctan.org/pkg/{datatool,filecontents}
\begin{document}
\begin{filecontents*}{chunk.csv}
AAAA,aaaaa
BBBB,bbbbb
CCCC,ccccc
DDDD,ddddd
EEEE,eeeee
FFFFF,fffffff
GGGGG,ggggg
HHHHHH,hhhhh
\end{filecontents*}
\DTLloaddb[noheader,keys={first,last}]{chunk}{chunk.csv}
\begin{itemize}
\DTLforeach{chunk}{\First=first,\Last=last}{\ifnum\value{DTLrowi}<4\relax\item \First, \Last\fi}
\end{itemize}
\hrulefill
\begin{itemize}
\DTLforeach{chunk}{\First=first,\Last=last}{\ifnum\value{DTLrowi}=4\relax\item \First, \Last\fi}
\end{itemize}
\hrulefill
\begin{itemize}
\DTLforeach{chunk}{\First=first,\Last=last}{\ifnum\value{DTLrowi}>4\relax\item \First, \Last\fi}
\end{itemize}
\end{document}
Low-level conditionals are used to (not) print each item, testing the value of DTLrowi
.
Best Answer
[EDIT Some how I missed @Gernot's comment. This answer is nothing more than an expanded version of what he wrote.]
I think that you have two problems.
tabular==|l|r|
should betabular=|l|r|
.\csvreader
command that are supposed to say how the table should be constructed.From your question it is not entirely clear to me what
data.csv
looks like so I have used the file:Changing your MWE to
you now obtain the table:
Note that
\thecsvrow
gives the row number and, for a given row,\csvcoli
gives the entry in column 1. There are also\csvcolii
,\csvcoliii
and so on. So the argument{\thecsvrow & \csvcoli}
to\csvreader
says that each of the table show start with the row index and then have the corresponding entry in column 1 of the data file.Finally, I'd recommend reading the manual from the booktabs package as it explains why you shouldn't use vertical rules in tables:)