0

I need to make a branch tree in LaTeX just like in the picture below. I need some help with the code. I don't know how to make it.

Branch tree

4

This needs some adjustment and polishing (e.g. I'm not clear what the algorithm for the labels is so mine is likely not quite right and some labels are likely explicitly specified without need) but if you use forest you can have a lot of the labelling handled automatically for you:

\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest}
\begin{document}
  \tikzset{
    every label/.append style={font=\scriptsize},
    my edge labels/.style={font=\scriptsize},
    dominant/.append style={label=below:$dominant$},
  }
  \begin{forest}
    for tree={
      circle,
      draw,
      minimum width=2.5em,
      l sep+=1.5em,
      s sep+=1em,
      anchor=center,
      edge path={
        \noexpand\path[\forestoption{edge}](!u.parent anchor)--(.child anchor)[my edge labels]\forestoption{edge label};
      },
    },
    delay={
      where n=1{
        edge label/.wrap 2 pgfmath args={
          node[midway, left]{$b_{#1}={#2}$}}{level}{n}
      }{
        edge label/.wrap 2 pgfmath args={
          node[midway, right]{$b_{#1}={#2}$}}{level}{n}
      },
    }
    [0, label={left:$L_2=L_3=3$}
      [1
        [2
          [3
            [4
            ]
            [12, label={below:$L_2=4$}
            ]
          ]
          [,phantom]
        ]
        [13, s sep+=1.5em, label={right:$L_3=3$}
          [{\phantom{a}}, dominant
          ]
          [14, label={below:$L_3=4$}
          ]
          [15, label={right:$L_3=3$}
            [, dominant
            ]
            [16, label={right:$L_3=3$}
            ]
          ]
        ]
      ]
    ]
  \end{forest}
\end{document}

forest power

EDIT

Tidied up the alignment etc. a bit, and used styles to ensure some consistency in formatting of labels etc.

| improve this answer | |
  • @PrzemysławScherwentke Thanks! I've tidied up slightly now. Glad I read the comments on the other answer or I would have been really perplexed by this comment! – cfr Oct 29 '14 at 22:47
1

You can use the tikz package and generate one as follows:

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\tikzstyle{level 1}=[sibling distance=30mm]
\tikzstyle{level 2}=[sibling distance=10mm]
\tikzstyle{level 3}=[sibling distance=5mm]
\tikzstyle{level 4}=[sibling distance=5mm]
\node{A}
    child
    {
        node{B}
            child
            {
                node{D}
                    child{node{H}}
                    child{node{I}}
            }
            child
            {
                node{E}
                    child{node{J}}
                    child{node{K}}
            }
    }
    child
    {
        node{C}
            child
            {
                node{F}
                    child{node{L}}
                    child{node{M}}
            }            
            child
            {
                node{G}
                    child{node{N}}
                    child{node{O}}
            }
    };
\end{tikzpicture}

\end{document}

enter image description here

You must read the tikz documentation in order to customize the tree according to your needs.

Also you can use the qtree package like this:

\documentclass{article}

\usepackage{qtree}

\begin{document}


\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]


\end{document}

Again qtree documentation will help you.

Source Wikipedia

enter image description here

| improve this answer | |
  • 1
    Now suppose one of you fathers is asked by his son for a fish; he will not give him a snake instead of a fish, will he? Or if he is asked for an egg, he will not give him a scorpion, will he? – Przemysław Scherwentke Oct 29 '14 at 3:56
  • What do you mean? – Adam Oct 29 '14 at 4:07
  • 1
    I am afraid that you answer is far from OP's expectations. In particular, there's no hint how to label connection of nodes. (And of course Luke 11:11-12 was cited). – Przemysław Scherwentke Oct 29 '14 at 4:26
  • This is everything he needs to create it. I used the exact same resources myself. I think is the best way to create a tree and by far the simplest. – Adam Oct 29 '14 at 4:39
  • Could you perhaps point out on which pages of the documentation you link to it is explained how to label the lines connecting the nodes of the trees? I have used qtree in the past, but there is much it cannot do and, looking quickly over the manual, I see no ready way to draw this tree. Also, it would be better to provide links to CTAN than to documentation on another site since the latter will not necessarily be updated when the package is updated and is likely to be less stable than resources on CTAN. For example qtree. – cfr Oct 29 '14 at 22:58

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.