# Difference between “right of=” and “right=of” in PGF/TikZ

In the PGF/TikZ manual, sometimes I see the option right of=somenode instead of right=of somenode. They look very similar, but the effects are different. The distance between nodes positioned with the latter option is boundary-to-boundary, as stated in the manual. However, with the first option, it seems that the distance is shorter. I couldn't find any explanation of the first option in the manual.

My question is: what is the difference between the two options? Is there any explanation in the manual that I missed?

-
A bookkeeping comment: in the v2.10 manual the deprecated above right of= appears on page 192 in the last example of /tikz/swap. –  equaeghe Oct 14 '12 at 9:26

The right of key isn't described in the manual at all (at least I couldn't find it). In fact, those keys are depreciated. The file pgf/frontendlayer/tikz/tikz.code.tex contains the following code:

% The following are deprecated:
\tikzoption{above of}{\tikz@of{#1}{90}}%
\tikzoption{below of}{\tikz@of{#1}{-90}}%
\tikzoption{left of}{\tikz@of{#1}{180}}%
\tikzoption{right of}{\tikz@of{#1}{0}}%
\tikzoption{above left of}{\tikz@of{#1}{135}}%
\tikzoption{below left of}{\tikz@of{#1}{-135}}%
\tikzoption{above right of}{\tikz@of{#1}{45}}%
\tikzoption{below right of}{\tikz@of{#1}{-45}}%
\def\tikz@of#1#2{%
\def\tikz@anchor{center}%
\let\tikz@do@auto@anchor=\relax%
\expandafter\tikz@extract@node@dist\tikz@node@distance and\pgf@stop%
\pgftransformshift{\pgfpointpolar{#2}{\tikz@extracted@node@distance}}}%
\def\tikz@node@at{\pgfpointanchor{#1}{center}}}
\def\tikz@extract@node@dist#1and#2\pgf@stop{%
\def\tikz@extracted@node@distance{#1}}


That is, the center of the new node is placed node distance away from the center anchor of the old node (where only the first number in node distance is used). You can see why this option is depreciated if you try a wide node:

\begin{tikzpicture}
\node (a) {loooooooooooooooooooooooooong};
\node[right of=a,font=\bfseries,blue] (b) {node b};
\end{tikzpicture}


On the other hand right=of would measure the node distance (defaulting to 1cm) from the east anchor of node a to the west anchor of node b:

Note that in order to use the right=of ⟨node⟩ syntax, you need to include the TikZ library positioning via \usetikzlibrary{positioning}.

-
Excellent answer. Thank you! –  Truong Jan 21 '11 at 5:34
Tip for others new to TikZ like me, "include the TikZ library positioning" requires \usetikzlibrary{positioning} as opposed to something such as \usepackage{tikz-positioning} –  Pat Jan 21 '13 at 4:15
@Pat: I added that bit of information to the answer. –  Caramdir Jan 21 '13 at 7:12