TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Welcome to TeX.sx! – Kurt Mar 2 '13 at 12:13
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. – Steven B. Segletes Mar 2 '13 at 12:14
p.s. I think your "would like" table has a typo in it (last row, last column should be 3...) – Steven B. Segletes Mar 2 '13 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 '13 at 12:57

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

share|improve this answer
@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 – Steven B. Segletes Mar 4 '13 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 '13 at 12:35
@soriak Still better version of getargs and alternative versions proposed by others at tex.stackexchange.com/questions/101604/… – Steven B. Segletes Mar 9 '13 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 '13 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? – Steven B. Segletes Mar 11 '13 at 11:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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