# Positioning of node with two measurements

The following quote is found Chapter 17, section 5.3 in the pgf manual. ("This option" refers to the specification of the location of a node by two measurements.):

The effect of this option is the following. First, the point (<number or dimension 2>, <number or dimension 1>) is computed using the normal rules for evaluating such a coordinate, yielding some position. Then, the node is shifted by the vertical component of this point. The anchor is set to south.

I am providing the example provided in the manual. Does the example illustrate "this option"? How does and 3mm change the position of the node?

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,shapes,positioning}

\begin{document}

\begin{tikzpicture}
\draw [help lines] (0,0) grid (2,2);
\node at (1,1) [above=0.2 and 3mm, draw] {over};
\end{tikzpicture}

\end{document}


Does anyone want to offer a better illustrative example?

• To use and 3mm you need to give above left or above right – user11232 Apr 18 '15 at 0:14
• @ Harish Kumar The manual says that "the reason (this option of using two measurements) is allowed for the above option is that it is sometimes automatically used," but it is almost always used for above left and similar options. Strangely, the only example the manual gives is using the above option! – Adelyn Apr 18 '15 at 0:55

The option doesn't work unless you add above right, above left or below right, below left. Also, you'll have different results if you leave the and 3mm out. Compare the following:

• [above right=0.2, draw]

• [above right=0.2 and 3mm, draw]

As explained in the quote, the anchor is set to the south of the node. The anchor is what is being "moved". The rest of the shape, of course, follows. If you don't know what anchors are, check the section 49 "Shapes" in the Tikz-Pgf manual (page 477). If you wanted you could set a different anchor, by adding the key anchor=north or anchor=north west in the options.

A circle would work the same way, except that the anchor is set to the center of the circle, not south. If you change your example to have \node at (1,1) [circle, draw] {over};, you'll see that it's positioned at the exact center, but if you add anchor=south, it will be moved up so that its south matches the center of the grid.

• The two displays you provide are different. Does the and 3mm move the node horizontally? What does above right =0.2 do with the node? My guess is that TikZ moves the node diagonally 0.2 centimeters. – Adelyn Apr 18 '15 at 0:21
• @Adelyn Yes, in the first case, it moves it diagonally. In the second case, it moves it 0.2 up and 3mm right/left. :) – Alenanno Apr 18 '15 at 0:22
• In the first example, it does look like the lower left corner is moved diagonally 2 millimeters and, in the second example, it does look like the lower left corner is moved one and a half times more rightward than upward. Thanks. (The manual did not say that!) – Adelyn Apr 18 '15 at 0:27
• @Adelyn Yes manuals don't always mention everything, but some things can be understood with some trial and error (and luck). :D – Alenanno Apr 18 '15 at 0:28
• You said above right=0.2 and 3mm moves "it" 2 millimeters up from the coordinate and 3 millimeters to the right. What is "it"? I guess it is the lower left corner of the box. What gets moved if I had below left=0.2 and 3mm? What happens with a circular node? – Adelyn Apr 18 '15 at 1:16

I think there is a need for some more clarification. First of all why there is no syntax error. That's because it saves a lot of if then syntax. Check out the internal code for these options in the archaic style of \tikzoption (which is equivalent to \tikzset)

\tikzoption{above}[]{\def\tikz@anchor{south}\tikz@possibly@transform{y}{}{#1}}
\tikzoption{below}[]{\def\tikz@anchor{north}\tikz@possibly@transform{y}{-}{#1}}
\tikzoption{above left}[]%
{\def\tikz@anchor{south east}%
\tikz@possibly@transform{x}{-}{#1}\tikz@possibly@transform{y}{}{#1}}


Now, you don't need to know what it does with possibly transforming etc. But you notice that if you give above, below etc. It discards the x information even if you provide explicitly 0.2 and 3mm.

Also you can see the opposite anchoring in effect: you choose one option and it chooses the opposite compass direction for anchoring. If you want to override it, you have to add explicit anchor=<foo> to your options.

By enabling a finer grid you can actually see the positioning better

%\usetikzlibrary{positioning}
\begin{tikzpicture}
\draw [help lines] (0,0) grid[step=1mm] (2,2) node at (1,1) {o};
\node at (1,1) [circle,above=0.2 and 3mm, draw] {over};
\end{tikzpicture}


And also with above right you get the exact amount of shift

%\usetikzlibrary{positioning,shapes.geometric}
\begin{tikzpicture}
\draw [help lines] (0,0) grid[step=1mm] (2,2) node at (1,1) {o};
\node at (1,1) [ellipse,above right=0.2 and 3mm, draw] {over};
\fill[red] (1,1) ++(3mm,2mm) circle(0.5pt);
\end{tikzpicture}


• Based on your reply, I understand that with the specification "0.2 and 3mm," TikZ ignores "3mm" if either above or below is specified, and TikZ ignores "0.2" if either "right" or "left" is specified. – Adelyn Apr 18 '15 at 15:51
• Your second example seems to illustrate that using above right is the same as using anchor=south east` and that the point on the ellipse that is the anchor is one of the two intersections of the line of slope 1 through the center of the ellipse with the ellipse. – Adelyn Apr 18 '15 at 17:08
• @Adelyn Yes the intersection of a ray from center and the shapeborder at 225 degrees (it can be a more complicated shape). – percusse Apr 20 '15 at 9:42