I wanted to use a pie chart in my document and tried this code example: http://www.texample.net/tikz/examples/pie-chart/

Now this seems to work perfectly with integer values but as for floating point I get errors.

Using this code


\foreach \p/\t in {1.5/type Windows, 10/type Linux}


I get this error:

Package calc Error: `.' invalid at this point. See the calc package documentation for explanation. Type H for immediate help. ... l.17 }

So I took a look into the documentation but could not find anything about this. I have also found this question here but using \real{1.5} and also just {1.5} did not help.

  • 2
    Well, \p contains 1.5 (in the first stage of the loop) and you can't add a floating point to a counter register
    – user31729
    Dec 28, 2015 at 15:58
  • You can use or adapt one of the answers to Pie chart with values as angles not percent
    – Ignasi
    Dec 28, 2015 at 17:37
  • In other words, use \newlength{a} and \addtolength{\a}{\p}. No idea where \slice came from. Dec 28, 2015 at 17:49
  • It would be easier to help if you added a correct minimal working example (MWE)
    – Rmano
    Dec 28, 2015 at 17:53

1 Answer 1


Counters only accept integer values.

You can use PGF tools or expl3:



  \fp_new:c { g_pie_#1_fp }
  \fp_gset:cn { g_pie_#1_fp } { #2 }
  \fp_use:c { g_pie_#1_fp }

  % slice
  \draw[thick,fill=black!10] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;
  % outer label
  \node[label=\midangle:#4] at (\midangle:1) {};
  % inner label
  \pgfmathsetmacro\innerpos{max(\temp,-0.5) + 0.8}
  \node at (\midangle:\innerpos) {#3};



\foreach \p/\t in {1.5/type Windows, 10/type Linux}



enter image description here

  • Thank you! But could you explain the first 2 lines in the foreach loop?
    – Someguy
    Jan 3, 2016 at 18:13
  • 1
    @Someguy Consider \setfpvar and \usefpvar as the analogs of \setcounter and \value.
    – egreg
    Jan 3, 2016 at 18:52
  • Yes I got that far too, but I am having trouble understanding why they obtain the values of p and t, and just what the order of these commands does exactly. I want to understand it so I can extend this method for more variables/slices.
    – Someguy
    Jan 3, 2016 at 19:42
  • 1
    @Someguy The instruction \declarefpvar is the analog of \newcounter; in \setfpvar you can use operations with the standard notations, as in the case of \setfpvar{b}{\p+\usefpvar{b}} that adds the value stored in \p to the value of the b variable and stores the sum in the variable a.
    – egreg
    Jan 3, 2016 at 20: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.