4

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.

enter image description here

5

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}
4
  • 1
    I also saw this possibility, but I would like to only scale the coordinates and to keep the text sizes, line thickness etc.
    – braxlan
    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.
    – pschulz
    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.
    – pschulz
    Feb 3 '17 at 13:49
  • 1
    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".
    – braxlan
    Feb 6 '17 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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