我有以下 TikZ 森林:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,automata,fit}
\usepackage{forest}
\tikzset{
>=stealth,
auto,
thick,
node distance=2.5cm,
transform shape,
}
\begin{document}
\begin{forest}
for tree={
child anchor=west,
parent anchor=east,
grow=east,
draw,
thick,
rounded corners=1mm,
anchor=west,
edge path={
\noexpand\path[\forestoption{edge}]
(.child anchor) -| +(-5pt,0) -- +(-5pt,0) |-
(!u.parent anchor)\forestoption{edge label};
},
}
[Bill
[Bob
[Rich
[Sam]
[Susan]
]
[Patty]
]
[Mary
[Mike]
[Kathy]
]
]
\end{forest}
\end{document}
生成图像:
这棵树从西向东“流动”。我一直在尝试锚点设置,看看能否让它从北向南生长,最低节点是 Bill 标记的节点(就像标准的家谱一样),但我似乎无法让边缘看起来正确且不重叠。
有什么建议么?
答案1
评论太长了。你的树的“流程”由键控制grow=east
,但你似乎想要grow=south
。然后你需要调整父母和孩子的锚点,正如你所预料的那样。请注意,你的\tikzset{...}
东西没有效果,所以我放弃了它。
\documentclass[tikz]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={parent anchor=south,child anchor=north,
draw,
thick,
rounded corners=1mm,
edge path={
\noexpand\path[\forestoption{edge}]
(!u.parent anchor) -- +(0,-5pt) -|
(.child anchor)\forestoption{edge label};
},
}
[Bill
[Bob
[Rich
[Sam]
[Susan]
]
[Patty]
]
[Mary
[Mike]
[Kathy]
]
]
\end{forest}
\end{document}
获得(几乎)相同结果的一种可能更简单的方法是仅使用,如果您加载库,即,则forked edges
可用。edges
\usepackage[edges]{forest}
\documentclass[tikz]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
forked edges,
for tree={grow=south,
draw,
thick,
rounded corners=1mm,
}
[Bill
[Bob
[Rich
[Sam]
[Susan]
]
[Patty]
]
[Mary
[Mike]
[Kathy]
]
]
\end{forest}
\end{document}