3

how can I get a third column "Z" in the output, where the values are e.g. 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}

This is how I would like it to look:

1]

4

Look at para. 4.3.2 of the pgfplotstable manual.

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

enter image description here

  • 2
    nice answer (+1)! i wasn't aware for this pgfplotsdtable possibility! apparently, i didn't read manual enough carefully :-( – Zarko Oct 27 '17 at 16:25
  • @Zarko Thank you! It's the first time I use pgfplotstable, I have just copied the instructions from the manual and adjusted them to fit the OP's case, LOL – CarLaTeX Oct 27 '17 at 16:28
  • @Zarko, one can do amazing stuff with pgfplotstable, also to its feature for pgfplots (two examples are given in my comment below the question). And there are even more awesome examples here on TeX.SX, but I am to lazy to search for them now. – Stefan Pinnow Oct 27 '17 at 18:02
  • @StefanPinnow, thank you for both links. i will analyse your answers and read manual again. so far i rarely use \pgplotstable (because my first impression was "very complicated" ... ; now it seems that i will change my mind :-) ). – Zarko Oct 27 '17 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.