如何使縮放影響 tikzpicture 中的 TikZ-pics?

如何使縮放影響 tikzpicture 中的 TikZ-pics?

我想在 TikZ 圖片中進行“全局縮放”,這也會影響tikzpicture環境中定義的所有圖片。微量元素:

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

為什麼 中定義的紅色方塊與square中繪製的綠色方塊不符tikzpicture?如何進行全域縮放,影響其中定義的所有圖片?我想避免手動縮放pic

在此輸入影像描述

答案1

transform shape是你的朋友。通常,像節點(顯然還有圖片)之類的東西不會縮放。使用transform shape,您可以強制執行此操作。請注意,這也會縮放文字。

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

相關內容