csvsimple 中标题行的颜色背景

csvsimple 中标题行的颜色背景

假设一个简单的例子csvsimple包裹。

\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}

在此处输入图片描述

尽管遵循包装文档(请参阅文档第 12 页),我发现很难让标题行具有灰色背景。有人能解释一下我的错误并提出可行的解决方案吗?

答案1

您需要使用[table]选项进行xcolor打包。还必须添加一些%以删除杂散空格。

\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}

在此处输入图片描述

相关内容