我正在想象一棵树在两个不同时间点之间的变化,到目前为止已经得出了以下结论:
\documentclass[12pt,paper=a4]{scrartcl}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
circle,
draw,
minimum size = 1pt
% font=\tiny
}
[, phantom, for children={fit=band}, s sep'+=60pt
[,
[,
[
[]
[]
]
[]
]
[,
[]
[]
]
[,
[]
[,name=left
[]
[]
]
]
]
[,
[,
[,name=right
[]
[]
]
[]
]
[
[,
[]
[]
]
[,
[]
[
[]
[]
]
]
]
]
]
\draw[-latex,double] (left) to (right);
\end{forest}
\end{document}
输出结果如下:
这没问题,但我更希望它看起来更像这样:
到目前为止,添加额外节点的所有实验均未成功。添加outer sep
节点看起来很奇怪,因为它还会向树的常规边缘添加填充。
无关,但也很有趣:我可以让树节点比现在更小吗?我知道minimum size
,但会对或类似的东西感兴趣maximum size
。
答案1
对于较短的箭头,最简单的解决方案是使用tikz
的shorten
键。
要使圆圈变小,请使用inner sep
— 节点无论如何都是空的。您可能还想forest
调整的l sep
和。l
s sep
(下面我也改成double
了very thick
。)
\documentclass[12pt,paper=a4]{scrartcl}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
circle,
draw,
inner sep=1pt,
l sep=5mm,
l=5mm,
s sep=2mm,
}
[, phantom, for children={fit=band}, s sep'+=60pt
[,
[,
[
[]
[]
]
[]
]
[,
[]
[]
]
[,
[]
[,name=left
[]
[]
]
]
]
[,
[,
[,name=right
[]
[]
]
[]
]
[
[,
[]
[]
]
[,
[]
[
[]
[]
]
]
]
]
]
\draw[-latex,very thick,shorten <=5mm,shorten >=5mm] (left) to (right);
\end{forest}
\end{document}
答案2
根据要求,这里有一个不影响根节点的方法phantom
。使用baseline
每个树中你想要与箭头对齐的节点。
\documentclass[border=10pt]{standalone}
\usepackage{forest}
\forestset{%
my tree/.style={
for tree={
circle,
draw,
inner sep=1pt,
l sep'=5mm,
l'=5mm,
s sep'=2mm,
},
}
}
\begin{document}
\begin{forest}
my tree,
[,
[,
[, baseline
[]
[]
]
[]
]
[,
[]
[]
]
[,
[]
[
[]
[]
]
]
]
\end{forest}
\begin{tikzpicture}
\draw [-latex,very thick] (0,0) -- +(60pt,0);
\end{tikzpicture}
\begin{forest}
my tree
[,
[,
[, baseline
[]
[]
]
[]
]
[
[,
[]
[]
]
[,
[]
[
[]
[]
]
]
]
]
\end{forest}
\end{document}