Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
2  
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
2  
\draw[dashed] (A) -- (B);? –  Harish Kumar Apr 2 '12 at 6:09
1  
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

1 Answer 1

up vote 1 down vote accepted

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}

output of code

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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