Pgfplotstable 和多行

Pgfplotstable 和多行

在以下示例中,我尝试使用规则排版表格pgfplotstableevery even row有没有办法针对某些给定列停用它?或者,有没有办法覆盖某些给定列的行颜色?

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

姆韦

我想要的是正确显示“数据”,而不是灰色multicolumn

编辑:我根据答案更改了我的 MWE,如您所见,现在包出了问题siunitx。这是因为#1在中使用了postproc,但我不知道如何修复它。

西伍

答案1

显然,\rowcolor他们\multirow不能很好地合作。

我尝试了debug切换来pgfplotstable验证这确实如此。解决方案似乎是\cellcolor使用每一个具有背景颜色的单元格。

我曾经postproc cell content插入过相应的\cellcolor说明(并且我every even row也融入了那种风格 - 显然,every even row并且postproc cell contents无法结合)。

解决方案如下:

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

在此处输入图片描述

相关内容