How can I make scaling affect TikZ-pics within a tikzpicture?

I want to have "global scaling" in a TikZ picture, which also affects all pics defined within a tikzpicture environment. MWE:

\documentclass[tikz, border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\draw [green] (0,0) rectangle (10,10);
\tikzset{square/.pic={\draw [red] (0,0) rectangle (10,10);}}
\draw (0,0) pic {square};
\end{tikzpicture}
\end{document}


Why does the red square defined in square not fit the green square drawn within the tikzpicture? How can I make the scaling global, affecting all pics defined within it? I would like to avoid scaling every pic by hand.

transform shape is your friend. Usually, stuff like nodes (and obviously pics) are not scaled. With transform shape, you can enforce this. Note that this also scales text.

\documentclass[tikz, border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.5, transform shape] % <--- Here!
\draw [green] (0,0) rectangle (10,10);
\tikzset{square/.pic={\draw [red] (0,0) rectangle node[midway, transform shape = false] { Foo } (10,10);}} % note the inserted, not transformed text node
\draw (0,0) pic {square};
\end{tikzpicture}
\end{document}

• I also saw this possibility, but I would like to only scale the coordinates and to keep the text sizes, line thickness etc. Feb 3 '17 at 11:03
• I edited my answer. You can use transform shape = false locally to disable the transformation. I will include a result Image, but i can't do this now. Try it out! This solution seems a bit impractical at first, but just incorporate this option into your styles (if you don't have any, start using them!) and you're fine. Feb 3 '17 at 11:18
• I just re-read your comment. I'm not sure how you would change only the coordinates, i will think about this. But i must say: this is the wrong approach. Make your shapes/objects the right size from the beginning on. If you need different sizes, use configurable sizes. Scaling is not meant for this kind of stuff. Feb 3 '17 at 13:49
• I am drawing objects from the real world, so it would be much more handy to use world coordinates and scale/transform them to "page coordinates". Feb 6 '17 at 7:23