如何使用 babel 包和 ngerman 选项定义字符串列表?

如何使用 babel 包和 ngerman 选项定义字符串列表?

我尝试制作饼图,但无法获得正确的标签:这是 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}

这会带来错误

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

我希望的输出如下所示:

在此处输入图片描述

没有标签,一切正常......

答案1

active"是一种babel简写,TikZ 库babel有助于:

\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{babel}

答案2

事实证明,这是来自 babel 包:双引号无法正确识别。\shorthandoff{"}这里的关键是:

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

希望这对某人有帮助,它花费了我小时小时帮助我找到了解决方案,并且与这个问题略有相似,所以我把是否将其标记为重复留给您自己决定。我认为这个问题正好相反,并提供了一条可能被搜索的错误消息...

相关内容