[Tex/LaTex] Pgfplotstable and multirow

pgfplotstabletables

In the following example, I'm trying to typeset a table using pgfplotstable with an every even row rule. Is there a way to deactivate it for some given columns ? Or alternatively, is there a way to override the color of rows of some given columns ?

\documentclass{article}
\usepackage{colortbl}
\usepackage{listings}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\pgfplotstabletypeset[
columns/Z/.style={
    column name={},
    assign cell content/.code={
        \ifnum\pgfplotstablerow=0
            \pgfkeyssetvalue{/pgfplots/table/@cell content}{\multirow{4}{*}{##1}}%
        \else
            \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
        \fi
    },
},
postproc cell content/.code={
    \ifodd\pgfplotstablerow\relax
    \else
        % ah - an even row number.
        \ifnum\pgfplotstablecol>0
            % ah - introduce a cell color:
            \pgfkeysalso{@cell content={\cellcolor[gray]{0.9}#1}}%
        \fi
    \fi
},
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
debug,
columns/a/.style={column name={A},
    column type={S[scientific-notation=engineering, round-precision=2, round-mode=places, table-format=2.2e1]}, string type,
},
row sep=\\, col sep=&]{% here: inline data in tabular format:
Z & a & b \\
data & 1.43 & 2 \\
     & 3.23 & 4 \\
     & 51231.2 & 6 \\
     & 0.007 & 8 \\
}
\end{document}

mwe

What I would like is to have "data" displayed correctly, without gray in the multicolumn.

EDIT: I have changed my MWE according to the answer, as you can see, something is wrong with the siunitx package now. This is because of using #1 in the postproc, but I don't know how to fix that.

WWO

Best Answer

Apparently, \rowcolor and \multirow do not work together in a good way.

I experimented with the debug switch of pgfplotstable to verify that this is, indeed, the case. A solution appears to use \cellcolor for every cell with bckground color.

I used postproc cell content to insert the appropriate \cellcolor instructions (and I incorporated every even row into that style as well - apparently, every even row and postproc cell contents cannot be combined).

Here is the solution:

\documentclass{article}
\usepackage{colortbl}
\usepackage{listings}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\thispagestyle{empty}

\pgfplotstabletypeset[
    columns/Z/.style={
        column name={},
        assign cell content/.code={
            \ifnum\pgfplotstablerow=0
                \pgfkeyssetvalue{/pgfplots/table/@cell content}{\multirow{4}{*}{##1}}%
            \else
                \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
            \fi
        },
    },
    postproc cell content/.code={
        \ifodd\pgfplotstablerow\relax
        \else
            % ah - an even row number.
            \ifnum\pgfplotstablecol>0
                % ah - introduce a cell color:
                \pgfkeysalso{@cell content={\cellcolor[gray]{0.9}#1}}%
            \fi
        \fi
    },
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule},
    debug,
    row sep=\\, col sep=&]{% here: inline data in tabular format:
    Z & a & b \\
    data & 1 & 2 \\
         & 3 & 4 \\
         & 5 & 6 \\
         & 7 & 8 \\
}


\begin {tabular}{ccc}%
\toprule &a&b\\\midrule %
\rowcolor [gray]{0.9}\multirow {4}{*}{data}&\pgfutilensuremath {1}&\pgfutilensuremath {2}\\%
&\pgfutilensuremath {3}&\pgfutilensuremath {4}\\%
&\cellcolor [gray]{0.9}\pgfutilensuremath {5}&\cellcolor [gray]{0.9}\pgfutilensuremath {6}\\%
&\pgfutilensuremath {7}&\pgfutilensuremath {8}\\\bottomrule %
\end {tabular}%

\end{document}

enter image description here

Related Question