我正在努力绘制系统发育树。
下面是一个最小的例子:
\documentclass[10pt]{article}
\usepackage{tikz}
\usepackage[edges]{forest}
\usetikzlibrary{trees,shapes,snakes}
\begin{document}
\begin{forest}
% insert coordinates in empty node
innov/.style={
edge label={node[auto, sloped,pos=.75,anchor=east]{#1}}
},
delay={where content={}{shape=coordinate}{}},
where n children=0{tier=word}{}, % align nodes at bottom of tree
for tree={
forked edge, % for forked edge
s sep = 2mm, % sibling distance
l sep = 6mm, % level distance
fork sep = 3mm, % distance from parent to branching point
}
[ to upper in the tree, text centered [, innov =innovation
[species 1][species 2]]
]
\end{forest}
\end{document}
我想要获得的内容如下图所示。按重要性递减顺序排列:
- 自定义应该独立于树级别
- 叉处的实心圆圈(这代表最后的共同祖先,因此从语义的角度来看非常重要)
- 水平线显示生物创新的出现
- 如果可以用自定义边而不是节点来表示生物创新,那就更好了,以简化节点层次结构并使其更类似于生物意义。
- 在 innovation 的最后一个字母和行之间留出更多空间(这不是很重要,我已经可以通过 ~ ~ 来增加这个空间了。
仅凭 1 和 2 就已经让我很开心了。
答案1
我认为这可以满足您的大部分需求。您可以创建节点样式dot
并进行设置fork sep=-1pt
(即点的半径)。该线可以是一个矩形节点,inner ysep=0pt
其右侧有一个标签。
\documentclass[10pt]{article}
\usepackage{tikz}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
% insert coordinates in empty node
innov/.style={
edge label={node[draw, minimum height=0pt, inner ysep=0, pos=.75, label={left:#1}]{}}
},
dot/.style={fill, circle, inner sep=0pt, outer sep=0pt, minimum size=2pt},
delay={where content={}{dot}{}},
where n children=0{tier=word}{}, % align nodes at bottom of tree
for tree={
forked edge, % for forked edge
s sep = 2mm, % sibling distance
l sep = 6mm, % level distance
fork sep = -1pt, % subtract half of minimum size
}
[ to upper in the tree, text centered [, innov =innovation
[species 1][species 2]]
]
\end{forest}
\end{document}
答案2
- “创新”增加了两个标签
- 点是单独绘制的
\documentclass[margin=3mm]{standalone}
\usepackage[edges]{forest}
\tikzset{
dot/.style={circle, fill, inner sep=1.2pt, node contents={}},
}
\begin{document}
\begin{forest}
for tree={
align = center,
forked edge, % for forked edge
s sep = 2mm, % sibling distance
l sep = 6mm, % level distance
fork sep = 4mm, % distance from parent to branching point
%
where n children=0{tier=word}{}, % align nodes at bottom of tree
delay={where content={}{shape=coordinate}{}},
}
[ to upper in the tree
[, label=center: -- , label=left:innovation\vphantom{p}, name=a
[species 1]
[species 2]
]
]
\path (a) ++ (0,-4mm) node[dot]; % vertical distance is equal to 4mm
\end{forest}
\end{document}
附录:
为了使forest
代码更短,可以方便地定义节点“创新”的样式,插入其两个标签。将其命名为inv
:
\documentclass[margin=3mm]{standalone}
\usepackage[edges]{forest}
\tikzset{
dot/.style={circle, fill, inner sep=1.2pt, node contents={}},
}
\begin{document}
\newcommand\fd{3mm} % <--- new, for common determining of fork distance
\begin{forest}
for tree={
align = center,
forked edge, % for forked edge
s sep = 2mm, % sibling distance
l sep = 6mm, % level distance
fork sep = \fd, % distance from parent to branching point
inv/.style = {label=center:--,label={[yshift=0.4ex]left: #1~~}}, % <-- new
%
where n children=0{tier=word}{}, % align nodes at bottom of tree
delay={where content={}{shape=coordinate}{}},
}
[ to upper in the tree
[, inv=innovation, name=a
[species 1]
[species 2]
]
]
\path (a) ++ (0,-\fd) node[dot]; % vertical distance is equal to fork sep
\end{forest}
\end{document}