我需要通过该样式的来改变样式color
的键的值。changeStyleColor
/utils/exec
/utils/exec
我可以通过设置全局键的值\tikzset{/tikz/myKey=myValue}
,也可以通过 设置位于用户定义目录中的键的值\tikzset{/tikz/myDirectory/myKey=myValue}
。但是我如何设置属于用户定义样式的键的值呢?
\documentclass{standalone}
\usepackage{tikz}
\tikzset
{ % global color
color=orange,
changeGlobalColor/.style=
{ /utils/exec=
{ \tikzset{/tikz/color=red}
}
},
changeDirectoryColor/.style=
{ /utils/exec=
{ \tikzset{/tikz/directory/color=green}
}
},
directory/.cd,
color/.initial=blue,
/tikz/.cd,
changeStyleColor/.style=
{ /utils/exec=
{ % how to change "pink" to something else?
},
color=pink
}
}
\begin{document}
\begin{tikzpicture}
% global color, orange (initial)
\path node(n1){n1};
% global color, red (changed from orange through /utils/exec)
\path node(n2)at(n1.south)[changeGlobalColor]{n2};
% directory color, green (changed from blue through /utils/exec)
\path node(n3)at(n2.south)[changeDirectoryColor,color=\pgfkeysvalueof{/tikz/directory/color}]{n3};
% style color, pink (initial); needs to be changed from pink to something else
% (through /utils/exec)
\path node(n4)at(n3.south)[changeStyleColor]{n4};
\end{tikzpicture}
\end{document}
答案1
您可以执行以下操作,但恕我直言,这非常违背此应用程序中 pgf 键的精神。
\documentclass{standalone}
\usepackage{tikz}
\tikzset
{ % global color
color=orange,
changeGlobalColor/.style=
{ /utils/exec=
{ \tikzset{/tikz/color=red}
}
},
changeDirectoryColor/.style=
{ /utils/exec=
{ \tikzset{/tikz/directory/color=green}
}
},
directory/.cd,
color/.initial=blue,
/tikz/.cd,
changeStyleColor/.style=
{ /utils/exec=
{ \tikzset{/tikz/directory/color=#1}
},
color=\pgfkeysvalueof{/tikz/directory/color}
}
}
\begin{document}
\begin{tikzpicture}
% global color, orange (initial)
\path node(n1){n1};
% global color, red (changed from orange through /utils/exec)
\path node(n2)at(n1.south)[changeGlobalColor]{n2};
% directory color, green (changed from blue through /utils/exec)
\path node(n3)at(n2.south)[changeDirectoryColor,color=\pgfkeysvalueof{/tikz/directory/color}]{n3};
% style color, pink (initial); needs to be changed from pink to something else
% (through /utils/exec)
\path node(n4)at(n3.south)[changeStyleColor]{n4};
\path node(n5)at(n4.south)[changeStyleColor=pink]{n5};
\end{tikzpicture}
\end{document}