# Color background for title row in csvsimple

Assume a simple example centered on the csvsimple package.

\documentclass{standalone}

\usepackage{csvsimple}
\usepackage{fp}
\usepackage{xcolor}

\begin{filecontents*}{input.csv}
Foo,Bar,Baz,Qux
A,1616,0.394,0.309
B,6999,0.336,0.999
C,261,0.378,0.284
D,171,0.332,0.386
E,402,0.428,0.241
\end{filecontents*}

\begin{document}

% COUNT THE ROWS
\edef\totalrows{\thecsvrow}

% VISUALIZE TABLE
table head=\hline \# & foo & bar & baz\\\hline\hline,
late after line=\\\hline,
filter expr={
test{\ifnumgreater{\thecsvinputline}{1}}
and test{\ifnumless{\thecsvinputline}{5}}
}
]{input.csv}{
Foo=\foo,
Bar=\bar,
Baz=\baz,
Qux=\qux
}
{\thecsvrow & \textit{\foo} & \bar & \baz}

\end{document}


Despite following the package documentation (see page 12 of the documentation), I find it hard to have the title row have a gray background. Can anyone explain my mistake here and propose a working solution?

You need to use the [table] option to xcolor package. Also had to add a few % to remove stray spaces.

\documentclass{standalone}

\usepackage{csvsimple}
\usepackage{fp}
\usepackage[table]{xcolor}
%\usepackage{xcolor}

\begin{filecontents*}{input.csv}
Foo,Bar,Baz,Qux
A,1616,0.394,0.309
B,6999,0.336,0.999
C,261,0.378,0.284
D,171,0.332,0.386
E,402,0.428,0.241
\end{filecontents*}

\begin{document}

% COUNT THE ROWS
\edef\totalrows{\thecsvrow}%
%
% VISUALIZE TABLE
table head=\hline \rowcolor{gray} \# & foo & bar & baz\\\hline\hline,
late after line=\\\hline,
filter expr={
test{\ifnumgreater{\thecsvinputline}{1}}
and test{\ifnumless{\thecsvinputline}{5}}
}
]{input.csv}{
Foo=\foo,
Bar=\bar,
Baz=\baz,
Qux=\qux
}
{\thecsvrow & \textit{\foo} & \bar & \baz}

\end{document}