
答案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}