# Writing a line from two sibling nodes in a TikZ tree

Recently I am struggling on TikZ and it is really difficult to find options and solutions considering it is such a huge and comprehensive library.

What I actually would like to do is drawing, in a tree, a line that connects two adjacent sibling nodes. That's all.

What is the best solution?

-
Just add a node name for each the nodes you want to connect and then use \draw to connect them. E.g. node (A) {XxX} and node (B) {YyY} will create nodes (A) and (B). Then at the end of your tree add \draw (A) -- (B); –  Alan Munn Apr 2 '12 at 4:33
Gonna try this... –  Andry Apr 2 '12 at 5:06
Post an answer man, you got this :) THANX a lot –  Andry Apr 2 '12 at 5:20
\draw[dashed] (A) -- (B);? –  Harish Kumar Apr 2 '12 at 6:09
Just have a look at the manual‌​. There is a chapter on Trees (18. Making Trees Grow). The second page of that chapter shows exactly what you want to do. It uses Alan's suggestion to do so (and Harish's to make it dashed). –  Roelof Spijker Apr 2 '12 at 8:21

It's sufficient to label any nodes that you want to connect and then simply use regular \draw commands to connect them. This is independent of what method you use to draw the trees. Below is a combined example using both regular TikZ tree methods or tikz-qtree methods (which provides a much less cumbersome syntax for most trees. In practice you would probably use one or the other.

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
% using regular TikZ tree methods
\begin{tikzpicture}
\node {A}
child {node (B) {B}
child {node {D}}
child {node {E}}}
child {node (C) {C}};
\draw[dashed] (B) -- (C);

\end{tikzpicture}
\bigskip

% using tikz-qtree
\begin{tikzpicture}[sibling distance=3em]
\Tree [.A
[.\node (B){B};
[.D ]
[.E ]
]
[.\node (C) {C}; ]
]
\draw[dashed] (B) -- (C);
\end{tikzpicture}
\end{document}


-