I'm new to pgfplots/pgfplotstable and got the following problem. I got a datafile like the following I use for plotting with pgfplots:

P1 P2 Value
1 1 0.00000000000e+00
1 2 1.00000000000e-02
1 3 0.00000000000e+00

2 1 1.00000000000e-02
2 2 1.00000000000e-02
2 3 3.00000000000e-02

I can plot this using pgfplots:

\addplot3[surf] table {../../results/testdatafile.dat};

Now I would like to add a table presenting the data like this:

P2/P1 1                 2
1     0.00000000000e+00 1.00000000000e-02
2     1.00000000000e-02 1.00000000000e-02
3     0.00000000000e+00 3.00000000000e-02

I couldn't figure out how to achieve this. Any help is appreciated.

  • I think the stringstrings package could be used to parse/extract terms from your input file, and then reassemble them as you wish. When I get to a system with LaTeX, I may follow up with an example (in a few days). The ease with which that can be done will depend on how predictable your datasets are. Mar 2, 2013 at 12:14
  • p.s. I think your "would like" table has a typo in it (last row, last column should be 3...) Mar 2, 2013 at 12:17
  • @StevenB.Segletes thanks for your answer, yes it's a typo I will correct it, I will have a look at stringstrings package and will post it here if I could achieve what I'm trying to.
    – soriak
    Mar 2, 2013 at 12:57

1 Answer 1


This uses the stringstrings \getargs command to grab/parse the data. Then I wrote a \readArray command to save it. Then I could recall the data into a tabular array from both tables. I could either invoke it using the saved variable names (1st table) or using the \Arrayij command (2nd table)

Currently, stringstrings array size is limited to a 500 character string, but that can be increased by modifying the following parameter in stringstrings.sty


I do not know how slow it will be for larger tables. stringstrings can be very slow, depending on the action.

For my simple example, I did not need to do that. Here is the code:



  \whiledo{\value{index} < \narg}{%
%    \arabic{index}:~
    \ifthenelse{\value{col} > #3}
%    \arabic{row}-\arabic{col}\\
      {\expandafter\csname arg\roman{index}\endcsname}



.15 12 13 14
.20 22 23 24
.25 32 33 Ending
.15 x12 x13 x14
.20 z22 x23 x24
.25 x32 x33 xEnding


Value & Data A & Data B\\
      & col3   & col3\\
\arAXiXi   & \arAXiXiii   & \arBXiXiii   \\
\arAXiiXi  & \arAXiiXiii  & \arBXiiXiii  \\
\arAXiiiXi & \arAXiiiXiii & \arBXiiiXiii \\

\ldots or you can use the $\backslash$Arrayij command to invoke the

Value & Data A & Data B\\
      & col4   & col4\\
\Arrayij{arA}{1}{1} & \Arrayij{arA}{1}{4} & \Arrayij{arB}{1}{4} \\
\Arrayij{arA}{2}{1} & \Arrayij{arA}{2}{4} & \Arrayij{arB}{2}{4} \\
\Arrayij{arA}{2}{1} & \Arrayij{arA}{3}{4} & \Arrayij{arB}{3}{4} \\

  • @soriak FYI, I've developed a faster version of \getargs found at tex.stackexchange.com/questions/100865/…, as long as you don't use a \$ in your datasets Mar 4, 2013 at 14:49
  • thanks for your answer. I had to do other stuff the last week. I will take a look now and give feedback, afterwards
    – soriak
    Mar 9, 2013 at 12:35
  • @soriak Still better version of getargs and alternative versions proposed by others at tex.stackexchange.com/questions/101604/… Mar 9, 2013 at 14:06
  • I added an output to my data generation which outputs the data in needed format. Since your version as well as all other that I found, need manual access to the entries in the matrix, it is not suitable for matrices with varying sizes. Thanks anyway?
    – soriak
    Mar 11, 2013 at 10:29
  • Sorry to hear it didn't work, but I'm not sure of your meaning "manual access". The \readArray takes as its second argument a specified but arbitrary array width, and reads a dataset of arbitrary array height. Ar you saying you want what amounts to a do loop on the tabular row creation? Mar 11, 2013 at 11:03

You must log in to answer this question.

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