Дерево рекурсии в LaTeX

Дерево рекурсии в LaTeX

Как можно нарисовать следующее дерево рекурсии в LaTeX?

в розыске

Я пробовал использовать TiкZ картинки для этого, но я продолжаю получать ошибки в коде. Пожалуйста, предложите более простой код для того же самого.

решение1

Вы можете использовать мощныйforestпакет; вы даже можете доверить пакету расчеты содержимого:

введите описание изображения здесь

Код:

\documentclass[border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{forest}

\begin{document}

\begin{forest}
for tree={
  parent anchor=south,
  s sep=2pt
},
delay={for descendants={
  if n=1
    {draw,content/.wrap 2 pgfmath args=
      {$c\binom{n}{#2}^{2}$}{content}{int(2^level)}}
      {if n'=1{draw,content/.wrap 2 pgfmath args=
        {$c\binom{n}{#2}^{2}$}{content}{int(2^level)}}{}
      },  
     where n children={0}{draw,content=c}{}
  }
}
[$cn^{2}$,draw
  [
    [
      [
        []
        []
        []
      ]
      [
        [,phantom]
      ]
      [
        [,phantom]
      ]
      [
        []
        []
        []
      ]
    ]
    [
      [,phantom]
    ]
    [
      [,phantom]
    ]
    [
      [
        []
        []
        []
      ]
      [
        [,phantom]
      ]
      [
        [,phantom]
      ]
      [
        []
        []
        []
      ]
    ]
  ]
  [
    [,phantom [,phantom]]
  ]
  [
    [,phantom [,phantom]]
  ]
  [
    [
      [
        []
        []
        []
      ]
      [
        [,phantom]
      ]
      [
        [,phantom]
      ]
      [
        []
        []
        []
      ]
    ]
    [
      [,phantom]
    ]
    [
      [,phantom]
    ]
    [
      [
         []
        []
        []
     ]
      [
        [,phantom]
      ]
      [
        [,phantom]
      ]
      [
        []
        []
        []
      ]
    ]
  ]
]
\end{forest}

\end{document}

решение2

forestпозволяет вам указать дерево, используя стандартную скобочную нотацию. Смотритемой ответ на предыдущий вопросдля объяснения того, как превратить дерево в спецификацию с помощью скобочной нотации. Другие ответы там охватывают другие пакеты, подходящие для рисования простых деревьев (как указано в вопросе). Так что если вам не нравится forest, возможно, подойдет что-то другое.

Для forestначала вот прототип:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\begin{document}

\begin{forest}
  for tree={
    draw,
    align=center
  }
  [root
    [child
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
      [grandchild, calign with current]
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
    ]
    [child
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
      [grandchild, calign with current]
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
    ]
    [child
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
      [grandchild, calign with current]
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
    ]
    [child
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
      [grandchild, calign with current]
      [grandchild
        [great\\-grandchild]
        [great\\-grandchild]
        [great\\-grandchild]
      ]
    ]
  ]
\end{forest}


\end{document}

опытный образец

Связанный контент