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}

원기

관련 정보