4

As a follow up question to draw an ellipse into a Tree picture -tikz package, how would one go about making a skinnier ellipse that encircles two horizontally and vertically offset nodes in a tree?

MWE

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{shapes,fit}

\begin{document}

\begin{tikzpicture}
    \Tree
    [.\node(1){asdfasdf};
        [.\node(2){hjklhjkl}; ]
        [.qwerqwer ]
    ]
    \node[draw,ellipse,fit=(1.north east)(2.south west)]{};
\end{tikzpicture}

\end{document}

Result

enter image description here

Desired result

(Line thickness and color are irrelevant; excuse the shakiness of my freehand drawing with a mouse.)

enter image description here

8

First idea: draw the elipse sloped along the path wich joins those nodes:

\begin{tikzpicture}
    \Tree
    [.\node(1){asdfasdf};
        [.\node(2){hjklhjkl}; ]
        [.qwerqwer ]
    ]

    \path (1.south) -- (2.north) 
      node[midway, sloped, draw, ellipse, 
           fit=(1.north east)(2.south west), inner sep=2pt]{};
\end{tikzpicture}

Result:

Result

Second idea: for finer control, \usetikzlibrary{calc} and the let..in syntax to compute the required size of the ellipse:

\begin{tikzpicture}
    \Tree
    [.\node(1){asdfasdf};
        [.\node(2){hjklhjkl}; ]
        [.qwerqwer ]
    ]

    \path let
         \p1 = ($(1.north east)-(2.south west)$),
         \n1 = {veclen(\p1)}
         in
         (1.south) -- (2.north) 
         node[midway, sloped, draw, ellipse, 
              minimum width=\n1, minimum height=\n1/2] {};
\end{tikzpicture}

Result:

Result2

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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