[Tex/LaTex] Latex Binomial tree (space and overlapping)

tikz-pgftikz-treestrees

I encounter the following problem: I want to fit a (vertical) binomial tree but the siblings from the third level overlap (no matter how I adjust the distances they either overlap with each other or they cross their cousins). What solution would you suggest? I've tried footnotesize font but it is not enough and I would like to keep the normal size. I thought maybe the children from parents $b_1 b_2$ and $b_2E[b_2]$ could be placed in the lower next Level but I don't know how to do that 🙁 Thanks a lot for your kind help!

\documentclass[12pt,a4paper,reqno,oneside]{amsart}
\usepackage{fancybox}
\usepackage{tikz}


\begin{document}
\begin{tikzpicture}[
baseline,
 level distance=20mm,
text depth=.1em,
text height=.8em,
level 1/.style={sibling distance=20em},
level 2/.style={sibling distance=10em},
level 3/.style={sibling distance=20mm}]


\node   (z){$b$}
child {node (a) {$b_1$}
child {node  (b) {$b_1 \, b_1$}
child {node {$b_1 \, b_1 \, b_1$}
} 
child {node {$b_1 \, b_1 \, b_2$}}
}
child {node (g) {$b_1 \, b_2$}
  child {node {$b_1b_2E[b_1]$}}
  child {node {$b_1b_2E[b_2]$}}
}
}
 child {node  (j) {$b_2$}
child {node  (k) {$b_2 \, E[b_1]$}
  child {node {$b_2 E[b_1b_1]$}}
  child {node {$b_2 E[b_1b_2]$}}
}
child {node  (l) {$b_2 \, E[b_2]$}
child {node {$b_2E[b_2]E[b_1]$}}
child {node (c){$b_2E[b_2]E[b_2]$}    
 }
 }
};
\path (a) -- (j) ;
\path (b) -- (g) ;
\path (k) -- (l) ;
\path (k) -- (g) ;
\end{tikzpicture}  

\end{document}  

Best Answer

Setting the trees to use 12pt font means they take more space than default. (Standard classes default to 10pt. standalone, which is often used to create graphics, defaults to 11pt.)

Here is a forest version with no adjustments:

\documentclass[12pt,tikz]{standalone}
\usepackage{forest}
\begin{document}
  \begin{forest}
    [{$b$}, name=z
      [{$b_1$}, name=a
        [{$b_1 \, b_1$}, name=b
          [{$b_1 \, b_1 \, b_1$}
          ]
          [{$b_1 \, b_1 \, b_2$}
          ]
        ]
        [{$b_1 \, b_2$}, name=g
          [{$b_1b_2E[b_1]$}
          ]
          [{$b_1b_2E[b_2]$}
          ]
        ]
      ]
      [{$b_2$}, name=j
        [{$b_2 \, E[b_1]$}, name=k
          [{$b_2 E[b_1b_1]$}
          ]
          [{$b_2 E[b_1b_2]$}
          ]
        ]
        [{$b_2 \, E[b_2]$}, name=l
          [{$b_2E[b_2]E[b_1]$}
          ]
          [{$b_2E[b_2]E[b_2]$}, name=c
          ]
        ]
      ]
    ]
    \path (a) -- (j) ;
    \path (b) -- (g) ;
    \path (k) -- (l) ;
    \path (k) -- (g) ;
  \end{forest}
\end{document}

forest version

At 172x42mm, this fits within A4 but not at all comfortably unless you rotate the tree.

So let's try a version which incorporates your suggested change:

\documentclass[12pt,tikz]{standalone}
\usepackage{forest}
\begin{document}
  \begin{forest}
    [{$b$}, name=z
      [{$b_1$}, name=a
        [{$b_1 \, b_1$}, name=b
          [{$b_1 \, b_1 \, b_1$}
          ]
          [{$b_1 \, b_1 \, b_2$}
          ]
        ]
        [{$b_1 \, b_2$}, name=g, for children={l+=2\baselineskip}
          [{$b_1b_2E[b_1]$}
          ]
          [{$b_1b_2E[b_2]$}
          ]
        ]
      ]
      [{$b_2$}, name=j
        [{$b_2 \, E[b_1]$}, name=k
          [{$b_2 E[b_1b_1]$}
          ]
          [{$b_2 E[b_1b_2]$}
          ]
        ]
        [{$b_2 \, E[b_2]$}, name=l, for children={l+=2\baselineskip}
          [{$b_2E[b_2]E[b_1]$}
          ]
          [{$b_2E[b_2]E[b_2]$}, name=c
          ]
        ]
      ]
    ]
    \path (a) -- (j) ;
    \path (b) -- (g) ;
    \path (k) -- (l) ;
    \path (k) -- (g) ;
  \end{forest}
\end{document}

adjusted tree

The adjusted tree measures 131x52mm which is well within A4.

Related Question