2

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
    \csvreader{input.csv}{}{}%
    \edef\totalrows{\thecsvrow}

    % VISUALIZE TABLE
    \csvreader[tabular=|c|l|c|c|,
    %table head=\hline \rowcolor{gray} \# & foo & bar & baz\\\hline\hline,  % NOT WORKING: \rowcolor not found
    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}

enter image description here

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?

1

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
    \csvreader{input.csv}{}{}%
    \edef\totalrows{\thecsvrow}%
%
    % VISUALIZE TABLE
    \csvreader[tabular=|c|l|c|c|,
    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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.