# How can label an edge of a tree which was manually added?

One can use TikZ to create a tree manually , or use the forest package to make the process easier. Below I show how I can use the forest package to create a binary tree, and turn it into a recombinant tree by using TikZ to draw some edges manually. While I can add a label to any edge which wasn't manually added (as I do below with the label Kangaroo), I cannot figure out how to add a label to an edge which was manually added. For example, how do I label the edge from the node $S_1(T)=4$ to the node $S_2(TH)=S_2(HT)=8$ (see the following picture)?

I simply tried copy-pasting the same command (i.e. edge label={node [near end, above left, font=\footnotesize]{Kangaroo}}) in the code below after (T) -- (TH), but it didn't work.

\begin{forest}
for tree={grow'=east}
[{$S_0=8$ },
[{$S_1(T)=4$ },name=T,
[{$S_2(TT)=2$}, edge label={node [near end, above  left, font=\footnotesize]{Kangaroo}} ]
[, phantom]
]
[, phantom
[{\qquad $S_2(TH)=S_2(HT)=8$},name=TH  ]
]
[{$S_1(H)=16$}, name=H
[, phantom]
[{$S_2(HH)=32$} ]
]
]
\draw (T) -- (TH)  (H) -- (TH);
\end{forest}


Fyi, the [,phantom] nodes are just empty nodes to help with spacing, they are not really necessary.

• please have a look at the answer to see if it meets your requirement – js bibra Sep 3 '20 at 1:00
• please have alook at the revised answer – js bibra Sep 4 '20 at 10:24
• This answers my question, thanks ! Fyi, I upvoted your answer, but it doesn't show because I am a noobie – ang Sep 6 '20 at 14:26
• you may like to accept the answer be clicking the green check mark on the left side of the answer – js bibra Sep 6 '20 at 14:59
• Ah ah! Done, thanks! Btw, if I may ask, what is the difference in behaviour between writing s sep=2em versus s=2em? – ang Sep 7 '20 at 16:30

You are looking for l sep dimension

Also the sloped version of label with positioning pos=0.5 or midway adjusted with the help of yshift

\begin{forest}
for tree={grow'=east, s sep=2em, l sep=2cm}
[{$S_0=8$ },
[{$S_1(T)=4$ },name=T,
[{$S_2(TT)=2$}, edge label={node [pos=0.5, above, yshift=-4pt ,sloped,
font=\scriptsize]{Kangaroo}} ]
[, phantom]
]
[, phantom
[{\qquad $S_2(TH)=S_2(HT)=8$},name=TH  ]
]
[{$S_1(H)=16$}, name=H
[, phantom]
[{$S_2(HH)=32$} ]
]
]
\draw (T) -- (TH)  (H) -- (TH);
\end{forest}


EDIT

\node at ($(T)!0.5!(TH)$)
[rotate=-22, yshift=5pt]
{\footnotesize\color{red} Kangaroo};


MWE

 \begin{forest}
for tree={grow'=east, s sep=2em, l sep=2cm}
[{$S_0=8$ },
[{$S_1(T)=4$ },name=T,
[{$S_2(TT)=2$}, edge label={node [pos=0.5,above,yshift=-4pt,sloped,
font=\footnotesize]{Kangaroo}} ]
[, phantom]
]
[, phantom
[{\qquad $S_2(TH)=S_2(HT)=8$},name=TH  ]
]
[{$S_1(H)=16$}, name=H
[, phantom]
[{$S_2(HH)=32$} ]
]
]
\draw (T) -- (TH)  (H) -- (TH);
\node at ($(T)!0.5!(TH)$)
[rotate=-22, yshift=5pt]
{\footnotesize\color{red} Kangaroo};
\end{forest}

• It looks like you misunderstood my question, so I have clarified it further. Sorry for the confusion – ang Sep 4 '20 at 10:00
• This answers my question, thanks ! – ang Sep 6 '20 at 14:26
• you may like to upvote the answer – js bibra Oct 20 '20 at 15:23