如何使用 Tikz 制作垂直组织结构图?

如何使用 Tikz 制作垂直组织结构图?

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}

在此处输入图片描述

相关内容