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