
在下面的範例中,我嘗試使用規則來排版pgfplotstable
表格every 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}