我试图将一组颜色存储在相应的 pgf 键中,然后稍后调用它。但是尝试这样做:
\documentclass{standalone}
\usepackage{pgf-pie}
\begin{document}
\pgfkeys{/colorsetA/.style={color={red,green,blue,orange}}}
\pgfkeys{/colorsetB/.style={color={orange,blue,magenta,yellow}}}
\begin{tikzpicture}
\pie[colorsetA]{10/A, 20/B, 30/C, 40/D}
\pie[pos={8,0}, colorsetB] {10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{document}
结果是Package pgfkeys Error: I do not know the key '/pgf/colorsetA' and I am going to ignore it. Perhaps you misspelled it. \pie[colorsetA]{10/A, 20/B, 30/C, 40/D}
我做错了什么,是我尝试访问了错误的密钥,还是我记得错误?
答案1
您需要在正确的范围内定义colorsetA
和。查找相对于的键,因此您需要colorsetB
pgf-pie
/pgfpie/
\documentclass{standalone}
\usepackage{pgf-pie}
\begin{document}
% CHANGED: Added /pgfpie
\pgfkeys{/pgfpie/colorsetA/.style={color={red,green,blue,orange}}}
\pgfkeys{/pgfpie/colorsetB/.style={color={orange,blue,magenta,yellow}}}
\begin{tikzpicture}
\pie[colorsetA]{10/A, 20/B, 30/C, 40/D}
\pie[pos={8,0}, colorsetB] {10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{document}
答案2
“root”键也有效,但您需要将其包含/
在\pie
参数中。如果您愿意,也可以使用\tikzset
。
\documentclass{standalone}
\usepackage{pgf-pie}
\begin{document}
\pgfkeys{/colorsetA/.style={color={red,green,blue,orange}}}
\tikzset{/colorsetB/.style={color={orange,blue,magenta,yellow}}}
\begin{tikzpicture}
\pie[/colorsetA]{10/A, 20/B, 30/C, 40/D}
\pie[pos={8,0}, /colorsetB] {10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{document}