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
.
\documentclass[]{article}
% \usepackage{csvsimple} % remove this for second solution
\usepackage{datatool} % add this for second solution
\usepackage{booktabs}
\usepackage[T1]{fontenc}
% \usepackage{underscore} %<- This solves your problem % remove this for second solution
\begin{document}
\section{csvreader}
% This works
% \csvreader[%
% respect all,%
% autotabular%
% ]{test.csv}{}{\csvlinetotablerow}%
\section{datatool simple}
\DTLloadrawdb[noheader,keys={a,b,c,d},headers={a,b,c,d}]{t2g}{test.csv}
\begin{table}[htbp]
\centering
\begin{tabular}{|c|c|c|c|}\hline
\DTLdisplaydb{t2g}
\\ \hline
\end{tabular}
\end{table}
% \DTLdisplaylongdb{iris}
\section{datatool not simple}
% This does not
\begin{table}[htbp]
\centering
\begin{tabular}{|c|c|c|c|}\hline
\DTLforeach{t2g}{\ca=a, \cb=b, \cc=c,\cd=d}%
{%
\DTLiffirstrow{}%
{%
\\ \hline
}
\ca&%
\cb&%
\cc&%
\cd%
}%
\\ \hline
\end{tabular}
\end{table}
\end{document}
What about this solution?
;)
Best Answer
Add
The default OT1 encoding doesn't have ascii symbols in the places you might expect.