I've been making tikz pictures for a while now, and there seem to be a number of different ways to position nodes within a diagram. Absolute coordinates, east/west, left/right, the $ $ things, minimum distance... Although I can find enough information on the internet to somehow get stuff to work, I'm having trouble seeing the big picture. Can anybody explain how all these different methods for node positioning work together, and how the computer actually figures out where the nodes should go?
You need to differentiate a few things:
at (<somewhere)part (or as a key:
<somewhere>can be any coordinate specification that is allowed by TikZ.
This may be an explicit coordinate like
<another node>.<with an anchor>.
This may also be an implicit coordinate like
(xyz cs: x=1, y=2),
(xyz polar cs: angle=30, radius=4)or
(node cs: name=<another node>, anchor=<with an anchor>).
Furthermore, you can give options at the begin of the coordinate specification which transform the specified coordinate, oftentimes, these are options like
xscaleand so on. These are the same options that can also be given on a path or a scope.
But this has nothing specifically to do with nodes because every coordinate on a path can be given in one of the mentioned ways.
If the node has no specified
atpart, the current position on the path is used (which is the origin at the start of the path).
So, the two following paths do the same:
\path ( 3, 2) coordinate (a) + ( 1, 0) coordinate (b) + ( 0, 1) coordinate (c) + (-1, 0) coordinate (d) + ( 0,-1) coordinate (e); \coordinate (a) at (3, 2) coordinate (b) at + (right:1) coordinate (c) at + ( up:1) coordinate (d) at + ( left:1) coordinate (e) at + ( down:1);
This specifies a point of the node itself that shall be placed at the
right(from here on called the
<somewhere>keys) internally set the anchor (
anchor=west). If a length is given with this option (
above left=1cm) a transformation in that direction is added. With our example, this means that the
.south eastanchor of the node is placed one centimeter away from the
atpart in the direction
<somewhere> of=<another node without an anchor>options (which are deprecated).
This key simply combine the
<somewhere>keys with the
atpart. You could also write:
at=(<another node without an anchor>),% the `.center` anchor is used anyway <somewhere>=<node distance>
<node distance>is the node distance set by the
They also set the anchor to
.centerbut you can change that, of course, if you just use the
anchorkey after the
<somewhere>keys that are enhanced/improved with the
positioninglibrary (should really be a default library if you work with a “noded” diagram).
If the value includes the text
of, some magic will happen (otherwise it’s just an ordinary
<somewhere>=<dimension>key-value pair, I think).
I believe the magic is already explained in another answer of mine. In summary: the
atpart is set (possibly specified with an anchor if an anchor-less node name is given), the
anchoris set (which is always
on gridoption is set), a transformation is also applied (which is dependent of the content of the
node distancekey (with or without
and) and the actual direction (“
poskey, yet another magical thing.
poskey is used on a node, the node is positioned along a (part of a) path. This is already explained in section 16.8 “Placing Nodes on a Line or Curve Explicitly” in pp. 190ff. of the PGF manual.
In the same section, the related keys
swapas well as
allow upside downare explained and short-cuts for the
poskey are listed.
Section 16.9 “Placing Nodes on a Line or Curve Implicitly” on pp. 193f. explain how that all plays in role if you use the node before the target of a path operator.