# Scaling “node distance” in tikz

Well, here's another TikZ question; this time, I have no idea how to find an answer. I would like to give all my nodes with relative coordinates:

\node (A) {A};
\node (B) [right = of A] {B};


using the positioning library. The distance is node distance. Unfortunately, it appears that passing the option scale = <factor> to {tikzpicture} does not have the desired effect on this distance; in fact, it does nothing. How can I give unit-free distances with relative coordinates?

-
Good question! A little experimenting shows that the instructions given via the "positioning" library are considered to be transformations of the node. They therefore are not usually affected by external transformations. As an example, consider putting rotate=180 on your example: B is still to the right of A. You can make external transformations apply to a node by using the key transform shape but then they apply to the node shape as well, which is not what is wanted. So there needs to be a key which says "apply the external transformation to the position but not the shape". –  Andrew Stacey Nov 17 '10 at 10:38
Well, since you bring it up, there's another place this occurs: using fit. This will transform a node so that it has both the correct size and the correct position to contain some given nodes. But what if I want to make a bunch of "containers" which are spaced enough to keep their contents apart? I have to draw the contents BEFORE the containers so that I can use fit to get the size, but then I can't reposition the containers. Nested {tikzpicture} seems to be the only way to get nodes within nodes like this. So, it would be nice if one could separate shape and position. –  Ryan Reich Nov 17 '10 at 11:21

Method 1 Apparently you don't have to give units to the node distance key. If you don't, it seems to take them as coordinates. So this scales the node distance to three times the default unit length, and the default unit length is the same as the default node distance.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\begin{scope}[node distance=3]
\node (A) {A};
\node (B) [right = of A] {B};
\end{scope}
\end{tikzpicture}
\end{document}


Method 2 after comments, consensus is that this is the preferred method It's possible to plot a point, read its coordinates, and set the node distance to that.

\begin{tikzpicture}[xscale=3]
\pgfpointtransformed{\pgfpointxy{1}{1}};
\pgfgetlastxy{\vx}{\vy}
\begin{scope}[node distance=\vy and \vx] % strange syntax here
\node (A) {A};
\node (B) [right = of A] {B};
\end{scope}
\end{tikzpicture}


Edit improvement that doesn't enlarge the bounding box invisibly from Andrew Stacey's comment. Thanks!

-
I'm not seeing a difference with the first method. Did you? –  Ryan Reich Nov 17 '10 at 13:57
Also, where does \pgfgetlastxy come from? I get an error trying that. It would be very useful... –  Ryan Reich Nov 17 '10 at 14:05
(1) Yes, and (2) section 76.6 of the PGF 2.10 manual. Sounds like we might have different versions. –  Matthew Leingang Nov 17 '10 at 14:30
@Ryan (and Matthew): The first method doesn't work: if I add rotate=180 then the nodes stay the same but everything else rotates. The second method does work. I'm using the latest (or nearly latest) pgf and it's in there. The file that the command is defined in is dated 2010/04/09 (presumably the last commit of that file to the VCS) so a version more recent than that will do. –  Andrew Stacey Nov 17 '10 at 14:36
Oh, but you should fix it so that the node (v) isn't involved in computing bounding boxes. –  Andrew Stacey Nov 17 '10 at 14:36