在以下 MWE 中,我尝试on use
根据另一列的定义创建一列on use
。在这种情况下,PGF 会产生错误:
PGFPlots: reading {test1.dat}
PGFPlots: reading {test2.dat}
! Package PGF Math Error: Unknown function `value__column_not_found' (in 'value
__column_not_found.*0.75').
尽管示例(取自这里) 很简单,我想将原始数据文件分开,但将一些结果以及一些简单的计算一起显示。有没有办法根据 中创建的另一个列创建一个列pgfplotstable
?
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotstableset{
create on use/lb/.style={
create col/expr={\thisrow{value}*0.75}
},
}
\begin{filecontents*}{test1.dat}
parameter
1
2
3
4
\end{filecontents*}
\begin{filecontents*}{test2.dat}
value
0.00034
0.0053
0.07
0.0027
\end{filecontents*}
\begin{document}
\pgfplotstableread{test1.dat}\parameter
\pgfplotstableread{test2.dat}\value
\pgfplotstabletypeset[
columns={parameter, value, lb},
columns/parameter/.style={
column name={Parameter},
},
columns/value/.style={
column name={Default Value},
},
create on use/value/.style={create col/copy column from table={\value}{value}},
columns/lb/.style={column name={Lower Bound}}.
]\parameter
\end{document}
答案1
\pgfplotstabletypeset
解决方案是使用宏将列复制到宏之外的表中\pgfplotstablecreatecol
。然后可以通过常规选项添加基于复制列的任何其他列create on use
。Jake 的回答不相关的问题让我走上正确的道路。
% arara: pdflatex
\documentclass{article}
\usepackage{pgfplotstable}
\begin{filecontents*}{test1.dat}
parameter
1
2
3
4
\end{filecontents*}
\begin{filecontents*}{test2.dat}
value
0.00034
0.0053
0.07
0.0027
\end{filecontents*}
\begin{document}
\pgfplotstableread{test1.dat}\parameter
\pgfplotstableread{test2.dat}\value
% This gets added
\pgfplotstablecreatecol[copy column from table={\value}{value}]{value}{\parameter}
\pgfplotstablecreatecol[expr={\thisrow{value}/\thisrow{parameter}}]{ub}{\parameter}
\pgfplotstableset{
create on use/lb/.style={
create col/expr={\thisrow{ub}*0.6}
},
}
%
\pgfplotstabletypeset[
columns={parameter, value, lb, ub},
columns/parameter/.style={
column name={Parameter},
},
columns/value/.style={
column name={Default Value},
},
columns/lb/.style={column name={Lower Bound}},
]\parameter
\end{document}
答案2
再次阅读手册,\pgfplotstablemodifyeachcolumnelemen 命令似乎并不比“create col/expr=”更有用。但“set list”方法有一些优势。
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\def\parameters{1,2,3,4}
\def\values{0.00034,0.0053,0.07,0.0027}
%demonstration of how to use \foreach: expr={} is more elegant.
\def\ub{}
\foreach \i in \values {\pgfmathmultiply{1.25}{\i}%
\ifx\ub\empty\global\edef\ub{\pgfmathresult}
\else\global\edef\ub{\ub,\pgfmathresult}
\fi}
\pgfplotstableset{create on use/parameter/.style={create col/set list/.expanded={\parameters}}}
\pgfplotstableset{create on use/value/.style={create col/set list/.expanded={\values}}}
\pgfplotstableset{create on use/lb/.style={create col/expr={\thisrow{value}*0.75}}}
\pgfplotstableset{create on use/ub/.style={create col/set list/.expanded={\ub}}}
\pgfplotstablenew[columns={parameter,value,lb,ub}]{4}\mytable
\pgfplotstabletypeset[
columns={parameter, value, lb, ub},
columns/parameter/.style={
column name={Parameter},
},
columns/value/.style={
column name={Default Value},
},
columns/lb/.style={column name={Lower Bound}},
columns/ub/.style={column name={Upper Bound}},
]\mytable
\end{document}