4

Can you use pgfplotstable to perform operations on columns?

For example, I have

\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}

Can I create a 3rd column z=x-y^2

1

1 Answer 1

3

You can create a new column as:

\pgfplotstableset{%
    create on use/MyValue/.style={
        create col/expr={\thisrow{x}-\thisrow{y}*\thisrow{y}}
    }
}

enter image description here

Code:

\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}
1
  • @mlainz: Your welcome. Have updated solution to provide a better formatted table. Nov 21, 2014 at 20:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .