6

I am using tikz-qtree, and I'd like to draw a curve separating a set of nodes from the rest of the tree. For example,

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}

\begin{document}
\begin{tikzpicture}[every node/.style={circle,draw,
                top color=white,bottom color=yellow!80,
                very thin},
                level distance=1.5cm,
                sibling distance=0.6cm]
  \Tree[.{$+$}
           [.{$*$}
               [.{$\cos$}
                   [.{$a$} ] ]
               [.{$2$} ] ]
               [.{$y$} ] ]
\end{tikzpicture}
\end{document}

produces this (sorry, I don't know yet how exactly to upload pictures to tex.stackexchange, so this ended up a bit small):

enter image description here

Now, I'd like to draw a (dotted) curve that crosses one edge (for example, the edge from * to cos) -- splitting the set of nodes in two (cos and a and all the others).

I know I can use the fit library to draw an ellipsis around the nodes, but I'd like an open line instead (more like a circumference arc, or a bezier curve).

What's the easiest way to do this?

8

You can use TikZ \nodes with names (See Section 4 Embedding TikZ nodes of the tikz-qtree documentation) and then draw the dotted line using any valid TikZ method. An example with a straight line:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tikz-qtree}

\begin{document}
\begin{tikzpicture}[every node/.style={circle,draw,
                top color=white,bottom color=yellow!80,
                very thin},
                level distance=1.5cm,
                sibling distance=0.6cm]
  \Tree[.{$+$}
           [.\node(ast){$*$};
               [.\node(cos){$\cos$};
                   [.{$a$} ] ]
               [.{$2$} ] ]
               [.{$y$} ] ]
\path[draw,dotted] ( $ (ast) + (-1,0) $) -- ++(-55:2.5);
\end{tikzpicture}
\end{document}

enter image description here

And an example with a curve:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tikz-qtree}

\begin{document}
\begin{tikzpicture}[every node/.style={circle,draw,
                top color=white,bottom color=yellow!80,
                very thin},
                level distance=1.5cm,
                sibling distance=0.6cm]
  \Tree[.{$+$}
           [.\node(ast){$*$};
               [.\node(cos){$\cos$};
                   [.{$a$} ] ]
               [.{$2$} ] ]
               [.{$y$} ] ]
\path[draw,dotted] ( $ (ast) + (-1,0) $) to[out=230,in=23] ++(-58:2);
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • Yes, but I don't want to connect nodes. I want the dotted curve to cross the edge between * and cos, but not connect nodes. – Jay Jun 15 '12 at 19:12
  • 1
    @Jay please see my updated answer. Is something like that what you want? – Gonzalo Medina Jun 15 '12 at 19:19
  • Hm, yes! Not a curve, but it's just fine. Thank you! – Jay Jun 15 '12 at 19:24
  • @Jay I just added an example with a curve. – Gonzalo Medina Jun 15 '12 at 19:25
  • Great! 8-) Even better! Thanks a lot! – Jay Jun 15 '12 at 19:26

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.