# Depth labels in Recursion Tree using Forest

I have a recursion tree very similar to the one below built using the Forest package. The only problem is that I do not know how to add labels to the right hand side for each depth of the tree. In other words, how do I get labels where the n's are in the diagram below. Thank you!

• Related (possible duplicate): tex.stackexchange.com/q/241232/4778 See the second answer for a solution with forest. – Alenanno Apr 6 '16 at 20:14
• @Alenanno I did see that and I have no idea how it works. I'm not using loops and I haven't been able to find any info in the Forest documentation regarding depth labels. Thank you though. – plast Apr 6 '16 at 20:22
• Well, what do you have? If the labels are the problem, give us the code for the tree and we'll show you how to add labels. Or see tex.stackexchange.com/questions/278683/…, for example. There are a number of questions about trees structurally identical to the one you've posted. The point of directing you to that question is precisely that it addresses what you're calling 'depth labels' so its not being in the documentation seems irrelevant: it is in the answers. – cfr Apr 6 '16 at 20:31

This is created using version 0.08 of an experimental package, justtrees based on Forest. (Copy available for testing on request.)

\documentclass[tikz,border=10pt]{standalone}
\usepackage{mathtools,justtrees}% version 0.08?
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{justtree}
{
declare count={tree n}{1},
just format={xshift=1.5em},
annotate/.style={% style should be applied to the rightmost node at each level for which an arrow and annotation is required
if n children=0{}{
right just=$n$,
},
},
where n children=0{
edge={dotted},
}{},
for tree={
math content,
if level=0{}{%
if level=1{%
tree n'=1,
}{%
if n=1{%
tree n/.wrap pgfmath arg={#1}{tree_n("!u")},
}{%
tree n/.wrap pgfmath arg={#1}{2*(tree_n("!u")},
},
},
},
delay={
if level=1{
content=n,
tikz+={
\draw [<->] (!F.south west) +(-2.5em,0) coordinate (c) -- (.north -| c) node [midway, anchor=south, sloped] {$Fomula$};
},
}{
if n children=0{%
}{
if level=0{}{
content/.wrap 2 pgfmath args={\frac{#1n}{#2}}{(tree_n()==1) ? "" : (tree_n())}{int(3^(level("!u")))},
}
}
}
},
},
}
[, annotate
[
[
[[][]]
[[][]]
]
[
[[][]]
[[][]]
]
]
[, annotate
[
[[][]]
[[][]]
]
[, annotate
[, annotate[][]]
[[][]]
]
]
]
\end{justtree}
\end{document}
• Thank you! Is justtrees one of your packages? I would a appreciate a copy. – plast Apr 7 '16 at 1:27
• – cfr Apr 7 '16 at 1:45
• It is a simplified version of prooftrees incompletely updated for v2 of Forest. But it does currently work. Or, if not, it will work very shortly. You meay need v2.0.3 of Forest - I'm not certain. I think there may be a bug in 2.0.2 which is the version on CTAN. If so, ask the author in the chat room about it. – cfr Apr 7 '16 at 1:49
• Thank you so much. I an unable to compile my document using Forest 2.0.2 and justtrees. I'll try to grab a copy of v2.0.3 of Forest and try with that. – plast Apr 7 '16 at 11:56
• @plast Please see here. Hopefully Sašo will be able to give you a link, tell me how to workaround the problem with 2.0.2 or suggest something else. I checked justtrees worked with version 2 of Forest but, unfortunately, I only discovered yesterday that 2.0.2 broke it. – cfr Apr 7 '16 at 12:29