# tikz: positioning of ellipse

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning,
shapes}

\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 9mm,
block/.style = {rectangle, draw, minimum height=22mm},
ellip/.style = {draw, ellipse, align=center},
]
\node (n1) [block] {block};
\node (n2) [ellip, above right=of n1.east]  {longer text\\ in two lines};
\node (n3) [ellip, below right=of n1.east]  {short\\ text};
\end{tikzpicture}
\end{document}


why the distance between ellipses and block are different? do i miss something in positioning of ellipses? it seems that the text in shapes are aligned instead of shapes ...

edit: after reading tikz & pgf manual again, i have impression, that ellipses is actually build from two shapes: one (of rectangle form) for text and one tight fit over for ellipses shape. it seems that distance defined by positioning library consider "inner" text shape. to see this, please change node distance = 3mm and 9mm, in above mwe to node distance = 1mm and 9mm. resuted image is than:

is this a bug?

• to my opinion lthe distances between shapes had to be equal. – Zarko Sep 25 '18 at 7:54

This is more like a comment. I do not think ellipses are special in this regard. To see that, consider the next shape of the shapes.geometric library, diamond, and compare.

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning,
shapes}

\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 9mm, %
block/.style = {rectangle, draw, minimum height=22mm},
ellip/.style = {draw, ellipse, align=center},
dia/.style = {draw, diamond, align=center},
]
\node (n1) [block] {block};
\node (n2) [ellip, above right=of n1.east]  {longer text\\ in two lines};
\node (n3) [ellip, below right=of n1.east]  {short\\ text};
\begin{scope}[xshift=6cm]
\node (m1) [block] {block};
\node (m2) [dia, above right=of m1.east]  {longer text\\ in two lines};
\node (m3) [dia, below right=of m1.east]  {short\\ text};
\end{scope}
\end{tikzpicture}
\end{document}


In neither case the distance really is the distance to the left-most point of the shape. And I cannot find any statement in the pgfmanual suggesting that this should be so.

Here come some more remarks, suggesting that it won't be trivial to have a version of positioning that really uses the distances between extremal points.

1. Measuring distances between extended objects is actually not completely trivial. Please look at the discussion of \pgfpointshapeborder{⟨node ⟩}{⟨point ⟩} on p. 1031 of the pgfmanual.
2. Another complication is that the bounding box of general shapes is tricky since the points relevant to the construction of curves are also taken into account in the bounding box, see e.g. here. To the best of my knowledge, so far there is no simple way to determine a tight bounding box of complicated shapes. Of course, as Skillmon points out in his answer for unrotated ellipses one could just use the standard anchors. Yet this will fail as soon as one considers rotated ellipses. Actually, as shown by this discussion, even circles may be difficult.

As long as we do not know how to precisely determine the extremal points of arbitrary shapes, I do not see a simple way of positioning things relative to each other with fixed distances between the (unknown) extremal points.

• no, this is not special to ellipse. i only discover this at using it. this seems to inherit to all shapes except rectangle. thank you for answer (+1). – Zarko Sep 25 '18 at 15:05
• @Zarko You're welcome! I believe a general solution won't be trivial, and added the reasons why I think so in my answer. (of course +1 for your question, you are right that, reading the discussion of positioning, it is not 100% clear what that really does...) – marmot Sep 25 '18 at 15:26
• thank you for adding valuable remarks to your answer! now i thing that the description of positioning and node distance (17.5.3 Advanced Placement Options, pages 229 -- 233) should be improved/clarified what we can expect with this library. i will wait for while if any of the package authors will add any explanation. – Zarko Sep 25 '18 at 15:53
• @Zarko If you really could get hold of the authors, perhaps you could convince them to optionally exclude the points that are used in the path construction but not part of the path from the bounding box. This would solve many open problems at once. One could do really cool things in 3D plots, for instance. – marmot Sep 25 '18 at 16:11
• This is way more than a comment. +1! – Skillmon Sep 25 '18 at 22:58

If you anchor them west the left borders of the ellipsis will be aligned:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning,
shapes}

\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 9mm,
block/.style = {rectangle, draw, minimum height=22mm},
ellip/.style = {draw, ellipse, align=center},
]
\node (n1) [block] {block};
\node (n2) [ellip, below right=of n1.north east,anchor=west]  {longer text\\ in two lines};
\node (n3) [ellip, above right=of n1.south east,anchor=west]  {short\\ text};
\end{tikzpicture}
\end{document}


• yes, this is workaround! however, at other shapes this is not needed! also positioning libraries determine distance between shapes (as far as i understand) ... – Zarko Sep 25 '18 at 7:53
• after testing i see new problems: vertical distance of ellipses ... see edit of my question. – Zarko Sep 25 '18 at 8:03
• @Zarko why should positioning consider the other anchor? It does position the adequate anchor at the specified distance from the anchor you used for reference. – Skillmon Sep 25 '18 at 10:22
• i expect that positioning of nodes works for all nodes shapes equal. but apparently it works only for rectangles. the same problem as with ellipses are with with circles. i will read manual again if this is somewhere noted. – Zarko Sep 25 '18 at 10:50
• @Zarko it does work the same way with ellipsis as it works with rectangles. If you specify a too small distance you get a too small distance. And it doesn't consider other nodes, just the two nodes in question, the new one and the one you use as reference. – Skillmon Sep 25 '18 at 10:56