我使用包创建了一个树状结构tikz
。我面临的问题是节点之间的距离不够,我想避免给出静态距离。我该如何处理?有没有什么方法可以让它自动工作?
\begin{figure}[h!]
\centering
\begin{tikzpicture}[ scale=.6,
every node/.style = { shape=circle,
draw, align=center}]]
\node {۱}
child {
node {۲}
child {
node {5}
child {
node {8}
}
child {
node{9}
child {
node{10}
}
child{
node{11}
}
}
}
child {
node{6}
child {
node{12}
}
child{
node{13}
child {
node{14}
}
child {
node{15}
}
}
}
child {
node{7}
}
}
child {
node{۳}
}
child {
node{۴}
}
;
\end{tikzpicture}
\caption{some caption.}
\end{figure}
在下图中你可以看到节点的重叠:
答案1
欢迎!如果您想避免此问题,请考虑切换到forest
。
\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={circle,draw,minimum size=2em}
[1
[2
[5
[8]
[9]
]
[6
[10
[12]
[13]
]
[11
[14]
[15]
]
]
[7]
]
[3]
[4]
]
\end{forest}
\end{document}
附录:这是您在评论中问的吗?
\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={circle,draw,minimum size=2em}
[1,alias=first
[2,alias=second
[5,alias=third
[8,alias=fourth]
[9]
]
[6
[10
[12,alias=fifth]
[13]
]
[11
[14]
[15]
]
]
[7]
]
[3]
[4]
]
\path ([xshift=-1em]current bounding box.west) coordinate (aux)
foreach \X in {first,second,third,fourth,fifth}
{(\X-|aux) node[left]{\X}};
\end{forest}
\end{document}