您可以使用 pgfplotstable 对列执行操作吗?
例如,我有
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotstableread{
x y
4 2.50000000e-01
16 6.25000000e-02
64 1.56250000e-02
256 3.90625000e-03
1024 9.76562500e-04
4096 2.44140625e-04
16384 6.10351562e-05
65536 1.52587891e-05
262144 3.81469727e-06
1048576 9.53674316e-07
}\mytable
\begin{document}
\begin{minipage}[t]{0.4\linewidth}
\pgfplotstabletypeset{\mytable}
\end{minipage}
\end{document}
我可以创建第三列 z=xy^2
答案1
您可以创建一个新列:
\pgfplotstableset{%
create on use/MyValue/.style={
create col/expr={\thisrow{x}-\thisrow{y}*\thisrow{y}}
}
}
代码:
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\pgfplotstableread{
x y
4 2.50000000e-01
16 6.25000000e-02
64 1.56250000e-02
256 3.90625000e-03
1024 9.76562500e-04
4096 2.44140625e-04
16384 6.10351562e-05
65536 1.52587891e-05
262144 3.81469727e-06
1048576 9.53674316e-07
}\mytable
\pgfplotstableset{%
create on use/MyValue/.style={
create col/expr={\thisrow{x}-\thisrow{y}*\thisrow{y}}
}
}
\begin{document}
\pgfplotstabletypeset[
every head row/.style={
before row={\toprule},
after row={
\cmidrule(lr){1-2}
\cmidrule(lr){3-3}
\cmidrule(lr){4-5}
}
},
every last row/.style={
after row={\bottomrule}
},
columns={x,y,MyValue},
columns/x/.style={column name=$x$, fixed,dec sep align},
columns/y/.style={column name=$y$, sci, column type=r},
columns/MyValue/.style={column name=$x-y^2$, fixed, dec sep align},
]{\mytable}
\end{document}