1

I try to make a pie chart, but can't get the labels right: This is the MWE:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{tikz}

\definecolorseries{colorser}{rgb}{last}{blue}{green}

\def\piechart#1#2#3#4#5{%1:data,2:numberOfElements,3:colors,4:outerRadius,5:labels
    \resetcolorseries[#2]{#3}
    \edef\startangle{90}
    \foreach [
        remember=\endangle as \startangle,
        evaluate=\i as \endangle using {\startangle-(\csname#1\endcsname[\i-1]/100*360)},
        evaluate=\halfangle using {(\endangle-\startangle)/2+\startangle},
    ] \i in {1,...,#2} {%
        \fill[{#3!![\i]}] (0,0) --++(\startangle:#4) arc (\startangle:\endangle:#4);
        \draw[white, line width=0.75mm](0,0)--++(\startangle:#4+0.1pt);
        \node at (\halfangle:#4) {\pgfmathparse{\csname#5\endcsname[\i-1]}\pgfmathresult};% With this line commented out there is no error...
    }
    \draw[white,line width=0.75mm](0,0)--++(\startangle:#4);
    \fill[white](0,0)circle [radius=#4*0.4];%
}

\begin{document}

\begin{tikzpicture}
    \newcommand\shares{{50,30,15,5}}
    \newcommand\labels{{"a","b","c","d"}}
    \piechart{shares}{4}{colorser}{2cm}{labels}
\end{tikzpicture}

\end{document}

This brings up the error

Argument of \language@active@arg" has an extra }. \par  ...piechart{shares}{4}{colorser}{2cm}{labels}

The output I hope for looks like that:

enter image description here

Without the labels, everything works...

3

The active " is a babel shorthand, TikZ library babel helps:

\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{babel}
  • Well, I didn't expect this to come true that fast... Learned something already!! – caligula Jun 8 '15 at 7:14
  • For example that I can't use this library with TikZ/PGF < 3.0 :( see here – caligula Jun 8 '15 at 7:25
1

It turned out that this comes from the babel package: The double quotation marks aren't recognized correctly. \shorthandoff{"} is the key here:

\shorthandoff{"}\newcommand\labels{{"a","b","c","d"}}\shorthandon{"}

Hope this helps someone, it cost me hours and hours. This helped me to find the solution and is slightly similar to this question, so I leave it up to you to mark this as duplicate or not. I think this question is the other way around and provides an error message that might be searched for...

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.