Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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

1 Answer 1

up vote 59 down vote accepted

The right of key isn't described in the manual at all (at least I couldn't find it). In fact, those keys are deprecated. 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%
  \tikz@addtransform{%
    \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 deprecated if you try a wide node:

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

example of incorrect positioning

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:

example of correct positioning

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

share|improve this answer
4  
Excellent answer. Thank you! –  Truong Jan 21 '11 at 5:34
5  
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
    
By default, positioning measures the distance between the borders of the nodes. But, with the on grid option, it measures the distance between the centers of the nodes. –  Paul Gaborit Jul 19 at 7:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.