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

Tomas
  • 23

2 Answers2

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.

cfr
  • 198,882
  • @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

Adam
  • 4,684
  • 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 03:56
  • What do you mean? – Adam Oct 29 '14 at 04: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 04: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 04: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
  • I have not searched qtree extensively yet, as I was too trying to create a tree for a document of mine yesterday. So I posted exactly the same material I was working on myself. I found in them extensive information so I wanted to give Tomas those information I spent hours searching. As I had never needed to draw large trees in the past yesterday when I had to do it I found out that it would be easier to simplify the process and produce a tree with the same information but with less "visual effects". So guessing that Tomas is in the same situation I find my answer quite proper. – Adam Oct 29 '14 at 23:05