I'm having a hard time understanding how TikZ uses space
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\tikzset{red/.style={fill=red,circle,inner sep=0pt}}
\tikzset{green/.style={fill=green,circle,inner sep=0pt}}
\begin{tikzpicture}[x=1cm,y=1cm]
\draw[help lines,step=.2] (-2,-1) grid (-1,0);
\draw[help lines,line width=.5pt,step=1] (-2,-1) grid (2,1);
\foreach \x in {-2,-1}
\node[anchor=north] at (\x,-1) {\x};
\foreach \y in {-1,0}
\node[anchor=east] at (-2,\y) {\y};
\node [rectangle,inner xsep=20mm,inner ysep=10mm,line width=.5pt](fr){};
\node [red,anchor=center] at (fr.south west){};
\node [green,anchor=center] at (-2,-1)(sw){};
\node [green,right=2mm of sw.center](r){};
\end{tikzpicture}
\end{document}
1) If you compile the above code you'll see that the red dot, which is placed with a relative coordinate, and the green one which is placed with numerical coordinates do not overlap perfectly. Why is that?
2) the node labeled r is not placed where it should be but a bit on the right, even if the distance is specified from sw.center. Why?
inner sep
of a node. If you changexsep=20mm,inner ysep=10mm
toinner xsep=0mm,inner ysep=0mm
the two are aligned exactly on top of each other. Sofr.south west
is not(-2.-1)
. The two are offset by the diagonal of the twoinner sep
s you added. Anohter possible confusion is that theanchor=center
refers to thecenter
of the new node you are placing, not the coordinate defined by theat
option.outer sep
(outer xsep
/outer ysep
) of.5\pgflinewidth
. Setting these to+0pt
places the anchors in the middle of the line. See also [1]. Theright
key automatically also setsanchor=west
(which is usually what you want), so you need to doright=2mm of sw.center,anchor=center
. Theon grid
option makes this the default behavior. See also [2] and [3].