
\node
使用和繪製矩形時minimum width/height
,產生的矩形的大小與使用 繪製的矩形的大小不同\draw … rectangle …
。我需要它\node
,這樣我就可以透過名稱來引用它。
我知道我可以透過將單位添加到所有尺寸(10 毫米、15 毫米)來解決這個問題,但我試圖理解為什麼沒有它就無法工作。我假設預設單位是<dimension>
點。
\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x = 1mm, y = 1mm]
%% named rectangle with minimum size of 10x15.
\node[%
minimum width = 10,
minimum height = 15,
draw = blue
]
(rect) at (0,0) {};
%% unnamed rectangle with size of 10x15.
\draw [red] (0,0) rectangle ++(10, 15);
\end{tikzpicture}
\end{document}
答案1
這與以下方面的轉變有關tikz
(參見PFG手冊第 373 頁)。其中一段明確指出:
座標變換最重要的方面是它僅適用於座標!
節點尺寸不受變換影響,預設單位為pt
。如果您希望尺寸像mm
已使用一樣工作,請將scale
和添加transform shape
到每個受影響節點的選項或使用全域選項。請參閱下面的範例
\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\tikzset{
x = 1mm, y = 1mm,
every node/.style = {
transform shape,
scale = 2.84, % Converts mm to pt by the factor 72.27/25.4
},
}
\begin{document}
\begin{tikzpicture}
%% named rectangle with minimum size of 10x15.
\node[%
minimum width = 10,
minimum height = 15,
draw = blue,
] (rect) at (0,0) {};
%% unnamed rectangle with size of 10x15.
\draw [red] (0,0) rectangle ++(10, 15);
\end{tikzpicture}
\end{document}