What I want to do is creating automatically the filenames of the datafiles inside a foreachloop in tikz. Maybe it's better to show a minimal example first:

    col sep=semicolon,
    x index=0,
    y index=1,





\begin{axis}[xlabel=$x$, ylabel=$y$]
    \foreach \A in {0.04,0.05,0.06} {
        \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}
        \addplot table {(TA\TA)(T\T).txt};


Inside this little tikz picture I want to do the following (and I have to do this for quite a big set of datafiles and different starting values).

  • First I want to define a starting value for \TA which I've done with \def...
  • Given the list of looping numbers i want to calculate for each loop a now variable \T which represents the sum of \TA and the current looping variable \A
  • Now, given this three numbers I want to load my data from my datafile (see preamble for filenames)

And here is my problem...

When the sum is equal to 0.10 I get the error:

... Could not read table file '(TA0.04)(T0.1).txt'. ...

because the value of \T is 0.1 and not 0.10.

Each numbers in my filenames have exactly two digits, but sometimes the last one is a zero as shown above. I tried to fix this with \pgfmathroundtozerofill{\T} but it does not work.

Has anybody an idea how I can fix this problem?? How can I fix the number of digits or add this zeros to the number???

P.S. Title seems to be the same than number formatting in foreach statement of tikz, but this question didn't helped me. Therefor I started a now one.

1 Answer 1


You almost had it, you only have to use \pgfmathresult instead of \T in your \addplot command. That's because \pgfmathroundtozerofill doesn't alter the contents of \T, but rather saves the result in \pgfmathresult.


You must log in to answer this question.

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