# Branches orientation in a tikz-tree

The folllowing code

\documentclass[border=10pt,varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, shapes, backgrounds}
\usepackage{amsmath, amssymb}
\begin{figure*}
\centering
\tikzset{
head/.style = {label = center:\textsf{\Large H}},
tail/.style = {label = center:\textsf{\Large T}}
}
\begin{tikzpicture}[
scale = 1.5, transform shape, thick,
every node/.style = {draw, circle, minimum size = 10mm},
grow = down,  % alignment of characters
level 1/.style = {sibling distance=4cm},
level 2/.style = {sibling distance=3cm},
level 3/.style = {sibling distance=2cm},
level distance = 1.25cm
]
\node[circle, draw, line width = 1pt,
minimum size = 10mm, inner sep = 0mm, font = \sffamily\large] (Start)
{root}
child { node [head] (A) {}
child { node [head] (B) {}}
child { node [tail] (C) {}}
}
child {   node [tail] (D) {}
child { node [head] (E) {}}
child { node [tail] (F) {}}
};

% Labels
\begin{scope}[nodes = {draw = none}]
\path (Start) -- (A) node [near start, left]  {$0.5$};
\path (A)     -- (B) node [near start, left]  {$0.5$};
\path (A)     -- (C) node [near start, right] {$0.5$};
\path (Start) -- (D) node [near start, right] {$0.5$};
\path (D)     -- (E) node [near start, left]  {$0.5$};
\path (D)     -- (F) node [near start, right] {$0.5$};
\end{scope}
\end{tikzpicture}
\end{figure*}


produces the output below

How coud modify the code to obtain a different orientation of the branches for some nodes? For example, as follows:

Moreover, what if I want to write different labels on different edges? For example 0.6 instead of 0.5 on the branch T-T?

## 1 Answer

with forest is relatively simple :-) :

• the first image:

\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}

\begin{document}
\begin{forest}
for tree={
circle,
draw, minimum size=8mm, font=\sffamily\Large, inner sep=1pt,
l sep = 18pt,
s sep =  6pt,
% labels on edges
EL/.style 2 args={
edge label/.wrap value={node[midway, font=\sffamily\footnotesize, #1] {#2}},
},
}, % end for tree
[root
[H,edge label=left
[H,EL={left}{0.1}
[H,EL={left}{0.3}]
[T,EL={right}{0.7}]
]
[T,EL={right}{0.9},
%calign=first
[H,EL={left}{0.6}]
[T,EL={right}{0.4}]
]
]
\end{forest}
\end{document}


• the second image:

\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}

\begin{document}
\begin{forest}
for tree={
circle,
draw, minimum size=8mm, font=\sffamily\Large, inner sep=1pt,
l sep = 18pt,
s sep =  6pt,
% labels on edges
EL/.style 2 args={
edge label/.wrap value={node[midway, font=\sffamily\footnotesize, #1] {#2}},
},
}, % end for tree
[H,EL={left}{0.1}
[H,EL={left}{0.5}]
[T,EL={right}{0.5}]
]
[T,EL={right}{0.9},
calign=first      % change branch direction
[H,EL={left}{0.5}]
[T,EL={right}{0.5}]
]
]
\end{forest}
\end{document}


edit: in both cases is now considered that each branch label can has different values.

• Thank you! But, what if I want to write different labels on different edges? For example 0.6 instead of 0.5 on the branch T-T? – Mark Jun 17 '18 at 10:22
• than you need to change code accordingly. this is not indicated in your mwe. please correct your mwe. – Zarko Jun 17 '18 at 10:46
• @Mark, see edited answer. – Zarko Jun 17 '18 at 11:00