6

I am having real trouble creating a tree. So far I have

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

\begin{document}

\begin{tikzpicture}[every tree node,
   level distance=1.25cm,sibling distance=1cm,
   edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}]
\Tree
[
    \edge node[auto=right,pos=.6] {$A$};
    [.1
       \edge node[auto=right,pos=.8] {$B$};
       [.2 ]
       \edge node[auto=left,pos=.8] {$C$};
       [.3 ]
        ]
    \edge node[auto=left,pos=.6] {$D$};
    [.4 ]
]
\end{tikzpicture}

\end{document}

which produces

enter image description here

However, I want to have two more layers, from 2 I want another 2 branches, and from the left of these branches I want another. Also how does one put a label underneath the numbers I have used?

Thank you very much and I hope I am clear

6
  • Use the forest package. Jan 14, 2015 at 18:04
  • 1
    Please make your code compilable by including \documentclass, relevant packages, etc.
    – Herr K.
    Jan 14, 2015 at 18:07
  • How exactly do you want the labels underneath the numbers? Can you add to your question an image (even a hand-drawn image) of the intended tree? Jan 14, 2015 at 18:11
  • Packages loaded were tikz, qtree and tikz-qtree.
    – iluvLatex
    Jan 14, 2015 at 18:14
  • I am unable to provide a picture, i would just like underneath each node a place i could put some text.
    – iluvLatex
    Jan 14, 2015 at 18:15

1 Answer 1

6

I'd suggest you to use the powerful forest package instead; it's more versatile, it has a lot of built-in features to customize trees and will give you shorter code. A simple example showing multi-line nodes:

enter image description here

The code:

\documentclass{article}
\usepackage{forest}

\begin{document}

\begin{forest}
for tree={
  l sep=30pt,
  parent anchor=south,
  align=center
}
[
  [1\\some text,edge label={node[midway,left]{A}}
    [2\\some text,edge label={node[midway,left]{B}}
      [4\\some text,edge label={node[midway,left]{C}}
        [6\\some text,edge label={node[midway,left]{D}}
        ]
        [7\\some text,edge label={node[midway,right]{E}}
        ]
      ]
      [5\\some text,edge label={node[midway,right]{F}}
      ]
    ]
    [3\\some text,edge label={node[midway,right]{G}}
    ]
  ]
  [8\\some text,edge label={node[midway,right]{H}}
  ]
]
\end{forest}

\end{document}
2
  • Perfecto! Thank you, i shall use the forrest command from now on.
    – iluvLatex
    Jan 14, 2015 at 18:38
  • @user70498 You're welcome! Don't forget that, after a sensible wait, you can accept the answer in case you consider it solved your problem. In case of doubt, please see How do you accept an answer?. Jan 14, 2015 at 18:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .