使用森林的递归树中的深度标签

使用森林的递归树中的深度标签

我有一个使用该Forest包构建的递归树,与下面非常相似。唯一的问题是我不知道如何为树的每个深度在右侧添加标签。换句话说,我如何获取标签,其中n 的如下图所示。谢谢!

enter image description here

答案1

justtrees这是使用基于 Forest的实验包 0.08 版本创建的。(可根据要求提供副本以供测试。)

annotated tree

\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}

相关内容