如何在输出中获得第三列“Z”,其中的值为 x*y
\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}
\usepackage{booktabs}
\begin{filecontents*}{data.dat}
x y
1 2
2 3
3 4
4 5
\end{filecontents*}
\pgfplotstableset{% global config, for example in the preamble
every last row/.style={after row=\bottomrule},
}
\begin{document}
\pgfplotstabletypeset[every head row/.style={before row={
\toprule},
after row=\midrule},
columns/x/.style={column name=x},
columns/y/.style={column name=y},
]{data.dat}
\end{document}
我希望它看起来是这样的:
答案1
参见第 4.3.2 段pgfplotstable 手册。
\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}
\usepackage{booktabs}
\begin{filecontents*}{data.dat}
x y
1 2
2 3
3 4
4 5
\end{filecontents*}
\pgfplotstableset{% global config, for example in the preamble
every last row/.style={after row=\bottomrule},
create on use/z/.style={
create col/expr={\thisrow{x}*\thisrow{y}}}
}
\begin{document}
\pgfplotstabletypeset[
every head row/.style={before row=\toprule,after row=\midrule},
columns={x,y,z},
columns/x/.style={column name=x},
columns/y/.style={column name=y},
columns/z/.style={column name=z},
]{data.dat}
\end{document}