我正在尝试根据单元格的内容为某些单元格的内容添加星号(本质上是添加一个标记来表示显著的 p 值),但我无法按列而不是按表进行操作。我改编了一个类似问题的答案根据数值对单元格进行着色但这似乎只有应用于整个表格时才有效。如果我尝试将样式应用于单个列(取消注释下面示例中的两行),我会收到一个Missing number, treated as zero.
错误,似乎期望在右方括号后输入一个数字而不是文件名。
\pgfplotstabletypeset [assume math mode=false,
% columns/a/.style={ % Uncommenting causes #1 to be empty
postproc cell content/.style={
/pgfplots/table/@cell content/.add={}{%
\pgfmathparse{int(less(#1,\bordervalue))}
\ifnum\pgfmathresult=1
$^*$
\else
$^\dagger$
\fi
},
},
% },
]{mwe.dat}
这似乎是因为,一旦我将postproc cell content
样式包装在column
样式中,它就不再有权访问该单元格的内容。,,,#1
和全部等于零,而始终等于整个表格的最后一个单元格的内容。@unprocessed cell content
@cell content after rowcol styles
@preprocessed cell content
@cell content
% #1 is empty when wrapped in a column style
\pgfplotstabletypeset [assume math mode=false,
columns/a/.style={
postproc cell content/.style={
/pgfplots/table/@cell content/.add={}{#1},
},
},
]{mwe.dat}
% @cell content contains the last cell of the whole table
\pgfplotstabletypeset [assume math mode=false,
columns/a/.style={
postproc cell content/.style={
/pgfplots/table/@cell content/.add={}{\pgfkeysvalueof{/pgfplots/table/@cell content}},
},
},
]{mwe.dat}
.code
使用而不是时结果类似.style
:
% Using .code, @cell content still only contains the very last cell of the table
\pgfplotstabletypeset [assume math mode=false,
columns/a/.style={
postproc cell content/.code={%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\pgfkeysvalueof{/pgfplots/table/@cell content}}%
},
},
]{mwe.dat}
完整 MWE:
\documentclass{article}
\usepackage{filecontents}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\pgfplotsset{compat=1.7}
\begin{filecontents}{mwe.dat}
a b c d e
1.7333 1.6472 1.5418 1.4682 1.5740
1.1525 1.2878 1.2652 1.3511 1.5102
1.2181 1.1500 1.2220 1.2425 1.5699
0.9786 1.1051 1.1472 1.3096 1.6757
0.9569 0.9190 1.0433 1.2924 1.4867
\end{filecontents}
\pgfplotstableset{
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
}
\begin{document}
\def\bordervalue{1.4}
\pgfplotstabletypeset [assume math mode=false,
% columns/a/.style={
postproc cell content/.style={
/pgfplots/table/@cell content/.add={}{%
\pgfmathparse{int(less(#1,\bordervalue))}
\ifnum\pgfmathresult=1
$^*$
\else
$^\dagger$
\fi
},
},
% },
]{mwe.dat}
\bigskip
\pgfplotstabletypeset [assume math mode=false,
columns/a/.style={
postproc cell content/.style={
/pgfplots/table/@cell content/.add={}{\pgfkeysvalueof{/pgfplots/table/@cell content}},
},
},
]{mwe.dat}
\bigskip
\pgfplotstabletypeset [assume math mode=false,
columns/a/.style={
postproc cell content/.append code={%
\ifnum\pgfplotstablerow=0
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\pgfkeysvalueof{/pgfplots/table/@cell content}}%
\fi
},
},
]{mwe.dat}
\end{document}
答案1
您可以在第一种方法中使用##1
而不是:#1
\documentclass{article}
\usepackage{filecontents}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\pgfplotsset{compat=1.7}
\begin{filecontents}{mwe.dat}
a b c d e
1.7333 1.6472 1.5418 1.4682 1.5740
1.1525 1.2878 1.2652 1.3511 1.5102
1.2181 1.1500 1.2220 1.2425 1.5699
0.9786 1.1051 1.1472 1.3096 1.6757
0.9569 0.9190 1.0433 1.2924 1.4867
\end{filecontents}
\pgfplotstableset{
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
}
\begin{document}
\def\bordervalue{1.4}
\pgfplotstabletypeset [assume math mode=false,
columns/a/.style={
postproc cell content/.style={
/pgfplots/table/@cell content/.add={}{%
\pgfmathparse{int(less(##1,\bordervalue))}
\ifnum\pgfmathresult=1
$^*$
\else
$^\dagger$
\fi
},
},
},
]{mwe.dat}
\end{document}