我正在尝试做一些与这篇文章非常相似的事情:
但是,我想根据另一列的内容对该列进行后处理。例如,如果相应的值大于 2,我想*
在该列中添加一个。coefficient
t-value
在表格中,通常我只报告和coefficient
,而standard error
不是t-value
。我想coefficient
根据的值对列进行后处理coefficient/standard error
。
以下是 MWE:
\documentclass{article}
\usepackage{pgfplotstable}
\begin{filecontents*}{test1.dat}
coefficient {standard error}
-.0159375 .008852
-.0107286 .0091658
.0042201 .0089453
.0108719 .0038041
\end{filecontents*}
\begin{document}
\pgfplotstableread{test1.dat}\results
\pgfplotstablecreatecol[expr={\thisrow{coefficient}/\thisrow{standard error}}]{t-value}{\results}
\def\bordervalue{2}
\pgfplotstabletypeset[
columns={coefficient, standard error, t-value},
columns/t-value/.style={
%preproc/expr = {100*##1},
postproc cell content/.style={
/pgfplots/table/@cell content/.add={}{%
\pgfmathparse{int(greater(##1,\bordervalue))}
\ifnum\pgfmathresult=1
$^*$
\fi
},
},
},
]\results
\end{document}
我怎样才能将 放入列*
中coefficient
,以便我不需要报告t-value
?
任何帮助都将受到赞赏。
答案1
你可以用一种巧妙的方法来做到这一点:
columns/coefficient/.style={
postproc cell content/.append code={%
\pgfplotstablegetelem{\pgfplotstablerow}{t-value}\of{\results}%
\pgfmathsetmacro{\TvalueTest}{\pgfplotsretval > \bordervalue ? 1 : 0}%
\ifthenelse{\TvalueTest = 1}% if
{\pgfkeysalso{/pgfplots/table/@cell content/.add={$}{*{}^*$}} }% then
{}% else
}},
顺便说一句:我简化了在列中添加星号的方法t-value
:
\pgfmathparse{##1 > \bordervalue ? "^*" : ""}\pgfmathresult
\documentclass[margin=5pt]{standalone}
%\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{ifthen}
\usepackage{colortbl}
\usepackage{filecontents}
\begin{filecontents*}{test1.dat}
coefficient {standard error}
-.0159375 .008852
-.0107286 .0091658
.0042201 .0089453
.0108719 .0038041
\end{filecontents*}
\begin{document}
\pgfmathsetmacro\bordervalue{2}
\pgfplotstableread[]{test1.dat}\results
\pgfplotstablecreatecol[expr={\thisrow{coefficient}/\thisrow{standard error}}]{t-value}{\results}
\pgfplotstabletypeset[
columns={coefficient, standard error, t-value},
columns/t-value/.style={numeric type,
postproc cell content/.style={
/pgfplots/table/@cell content/.add={$}{
\pgfmathparse{##1 > \bordervalue ? "^*" : ""}\pgfmathresult$ % New
},},
},
% New:
columns/coefficient/.style={
postproc cell content/.append code={%
\pgfplotstablegetelem{\pgfplotstablerow}{t-value}\of{\results}%
\pgfmathsetmacro{\TvalueTest}{\pgfplotsretval > \bordervalue ? 1 : 0}%
\ifthenelse{\TvalueTest = 1}% if
{\pgfkeysalso{/pgfplots/table/@cell content/.add={\cellcolor{pink}$}{*{}^*$}}}% then
{}% else
}},
]\results
\end{document}