这是我目前的代码:
\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}[every tree node/.style={font=\huge},
level distance=1.1cm,sibling distance=.8cm,
edge from parent path={(\tikzparentnode.south) -- +(0,-8pt) -| (\tikzchildnode)}],
frontier/.style={distance from root=350pt} % Align leaf nodes
\Tree
[
\edge node[near end,left] {branch};
[
\edge node[near end, left] {};
[
\edge node[] {}; [.a ]
\edge node[] {}; [.b ]
]
\edge node[] {}; [.c ]
]
\edge node[near end,right] {};
[
\edge node[] {}; [.d ]
\edge node[] {}; [.e ]
]
]
\node[draw] at (0,.2) {root};
\draw (1.6,-1.9) circle (1.3cm);
\draw[thick,->] (0,-4.5) -- (1,-3.2);
\node[draw] at (0,-5) {clade};
\end{tikzpicture}
\end{document}
生成以下内容(PDFLaTex):
我的问题是:
- 如何让所有的叶子出现在同一个水平面上?
- 除了手动定位树上的位置之外,有没有更好的绘制圆圈的方法?
- 如何让树水平?
答案1
您可以使用该fit
库将节点适配到一组命名节点中。如果您使用 Forest 绘制树,它会提供fit to=<nodewalk>
包装器来简化此操作。
例如,
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{shapes.geometric,arrows.meta}
\begin{document}
\begin{forest}
forked edges,
/tikz/every pin edge/.append style={Latex-, shorten <=2.5pt, darkgray},
/tikz/every pin/.append style={darkgray, font=\sffamily},
/tikz/every label/.append style={darkgray, font=\sffamily},
before typesetting nodes={
delay={
where content={}{coordinate}{},
},
where n children=0{tier=terminus, label/.process={Ow{content}{right:#1}}, content=}{},
},
for tree={
grow'=0,
s sep'+=10pt,
l sep'+=15pt,
},
l sep'+=50pt,
tikz+={
\node [draw=blue, circle, ellipse, densely dashed, fit to={1,tree}, pin={[pin distance=50pt,name=clades]-40:clades}] {};
\node (p) [draw=blue, circle, ellipse, densely dashed, fit to={l,tree}] {};
\draw [every pin edge] (p) -- (clades);
}
[, !l.edge label={coordinate [pos=0, pin=-135:root] }, !1.edge label={node [pos=.65, every label, above] {branch}}, !11.edge label={coordinate [pos=0, pin={[pin distance=30pt, align=center]135:internal\\node}] }
[
[
[tip (terminal node)]
[b]
]
[c]
]
[[d][e]]
]
\end{forest}
\end{document}