有没有办法将默认选项传递给pic
?在 MWE 中,选项transform shape
被传递给图片实例。是否可以将此选项设为所有图片的默认选项,square
这样就不需要将其传递给所有实例了?
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\tikzset{pics/square/.style={code={\fill[#1] (0,0) rectangle (1,1);}}}
\draw (-1,-1) grid (2,2);
\pic {square=green};
\pic[transform shape] {square=red};
\end{tikzpicture}
\end{document}
答案1
您可以设置一个带有样式的键不同的路径通过调用完整路径。的完整路径transform shape
为/tikz/transform shape
:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[
scale=0.8,
pics/square/.style={
/tikz/transform shape,
code={\fill[#1] (0,0) rectangle (1,1);}
}
]
\draw (-1,-1) grid (2,2);
\pic {square=green};
\pic {square=red};
\end{tikzpicture}
\end{document}
结果: