3

Is there a way to pass default options to a pic? In the MWE, the option transform shape is passed to an instance of a pic. Is it possible to make this option the default for all pics square such that one does not need to pass it to all instances?

\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}

enter image description here

  • 1
    Not an answer to your question, but if you use \tikzset{pics/square/.code={\fill[#1] (0,0) rectangle (1,1);}}, the transform shape is not needed. – Max Jan 9 at 12:48
6

You can set a key with a style in a different path by calling the complete path. The complete path of transform shape is /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}

Result:

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.