# Pgfplotstable and multirow

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


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.

-
Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you. – hpesoj626 Apr 2 '13 at 10:35

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


-
This is what I had in mind first, unfortunately this breaks something with the siunitx package, c.f. my edit. Thanks anyway – BigDawg Apr 7 '13 at 8:15
I see and I understand why: siunitx attempts to format the cell containing \cellcolor. Perhaps you need to avoid the S column type and invoke the number printer manually to combine them. Perhaps @JosephWright can shed some light on it. – Christian Feuersänger Apr 7 '13 at 11:14