![如何使用 Tikz 制作垂直组织结构图?](https://linux22.com/image/447714/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20Tikz%20%E5%88%B6%E4%BD%9C%E5%9E%82%E7%9B%B4%E7%BB%84%E7%BB%87%E7%BB%93%E6%9E%84%E5%9B%BE%EF%BC%9F.png)
Tikz
我正在尝试使用和库创建垂直组织结构图trees
。但是,它们之间连接不同元素的线条并没有像我希望的那样显示出来。
确实,我想获得一个“垂直”图,因此我将below = ... of ...
元素一个接一个地放置,但是连接线显示在文本框的前面而不是后面,这是我不想要的,如下图所示:
此外,通过该rounded corners
选项,我得到了以下信息:
当我认为得到这样的结果更合乎逻辑时:
该怎么办呢?
这是我的 MWE:
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning, trees}
\begin{document}
\begin{tikzpicture}[
childStyle/.style={text width=3cm},
level 1/.style={childStyle, sibling distance=35mm, nodes={fill=red!50}},
level 2/.style={nodes={fill=red!25}},
]
\node[fill=red!75]{Blah blah blah}[edge from parent fork down, rounded corners=6pt]
child{node (A) {Blah blah blah}
child {node[below = 5mm of A] (A1) {Blah blah blah}}
child {node[below = 5mm of A1] (A2) {Blah blah}}
child {node[below = 5mm of A2] (A3) {Blah blah blah}}
child {node[below = 5mm of A3] (A4) {Blah}}
}
child{node (B) {Blah blah}
child {node[below = 5mm of B] (B1) {Blah blah}}
child {node[below = 5mm of B1] (B2) {Blah blah blah blah blah blah}}
}
child{node (C) {Blah blah blah}
child {node[below = 5mm of C] (C1) {Blah blah}}
child {node[below = 5mm of C1] (C2) {Blah blah}}
child {node[below = 5mm of C2] (C3) {Blah blah blah}}
};
\end{tikzpicture}
\end{document}
答案1
使用forest
包装很简单:
\documentclass[border=3.141592mm]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree = {
% nodes
text width=32mm,
outer sep=0pt,
if level=0{fill=red!50}{rounded corners, fill=red!20},
if level=1{fill=red!50}{},
% tree
parent anchor=south,
child anchor=north,
% edges
forked edge,
s sep = 2mm,
l sep = 4mm,
fork sep = 2mm, % distance from parent to branching point
edge = {semithick, rounded corners=3pt},
}
[Blah blah blah, name=root
[Blah blah blah
[Blah blah blah
[Blah blah
[Blah blah blah
[Blah]
] ] ]
]
[Blah blah blah, name=middle, no edge
[Blah blah blah
[Blah blah blah blah blah blah]
]
]
[Blah blah blah
[Blah blah
[Blah blah
[Blah blah blah]
] ]
]
]
\draw[semithick] (root) -- (middle);
\end{forest}
\end{document}