Latex 中的组织结构图。节点之间的垂直距离

Latex 中的组织结构图。节点之间的垂直距离

我想以组织结构图的形式绘制组织结构。我发现解决方案并尝试进行调整。代码如下:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees}

\begin{document}

\tikzset{
  basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
  root/.style   = {basic, thin, align=center,
               fill=gray!45},
  level 2/.style = {basic, thin,align=center, fill=gray!30,
               text width=8em},
  level 3/.style = {basic, thin, align=left, fill=gray!20, text width=6.5em}
}
\begin{tikzpicture}[
  level 1/.style={sibling distance=40mm},
  edge from parent/.style={->,draw},
  >=latex]

% root of the the initial tree, level 1
\node[root] {Group Key Management}
% The first level, as children of the initial tree
  child {node[level 2] (c1) {Centralized}}
  child {node[level 2] (c2) {Decentralized}}
  child {node[level 2] (c3) {Distributed Key Agreement}};

% The second level, relatively positioned nodes
\begin{scope}[every node/.style={level 3}]
\node [below of = c1, xshift=15pt] (c11) {Pairwise Keys};
\node [below of = c11] (c12) {Broadcast Secrets};
\node [below of = c12] (c13) {Keys Hierarchy};

\node [below of = c2, xshift=15pt] (c21) {Membership driven Re-Keying};
\node [below of = c21] (c22) {Time driven Re-Keying};

\node [below of = c3, xshift=15pt] (c31) {Ring-based Cooperation};
\node [below of = c31] (c32) {Hierarchical Cooperation};
\node [below of = c32] (c33) {Broadcast Cooperation};
\end{scope}

% lines from each level 1 node to every one of its "children"
\foreach \value in {1,2,3}
  \draw[->] (c1.195) |- (c1\value.west);

\foreach \value in {1,2}
  \draw[->] (c2.195) |- (c2\value.west);

\foreach \value in {1,2,3}
  \draw[->] (c3.195) |- (c3\value.west);
\end{tikzpicture}

\end{document}

结果是

结果

如您所见,框之间的垂直距离很难看,因为我的一些框比相应的兄弟框的线条更多。我可以做些什么来使一个父级下的所有框的距离至少相同?

答案1

您可以node distance按如下方式使用密钥(在 中更改level 3):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees}

\begin{document}

\tikzset{
  basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
  root/.style   = {basic, thin, align=center,
               fill=gray!45},
  level 2/.style = {basic, thin,align=center, fill=gray!30,
               text width=8em},
  level 3/.style = {basic, thin, align=left, fill=gray!20, text width=6.5em, node distance = 40pt}
}
\begin{tikzpicture}[
  level 1/.style={sibling distance=40mm},
  edge from parent/.style={->,draw},
  >=latex]

% root of the the initial tree, level 1
\node[root] {Group Key Management}
% The first level, as children of the initial tree
  child {node[level 2] (c1) {Centralized}}
  child {node[level 2] (c2) {Decentralized}}
  child {node[level 2] (c3) {Distributed Key Agreement}};

% The second level, relatively positioned nodes
\begin{scope}[every node/.style={level 3}]
\node [below of = c1, xshift=15pt] (c11) {Pairwise Keys};
\node [below of = c11] (c12) {Broadcast Secrets};
\node [below of = c12] (c13) {Keys Hierarchy};

\node [below of = c2, xshift=15pt] (c21) {Membership driven Re-Keying};
\node [below of = c21] (c22) {Time driven Re-Keying};

\node [below of = c3, xshift=15pt] (c31) {Ring-based Cooperation};
\node [below of = c31] (c32) {Hierarchical Cooperation};
\node [below of = c32] (c33) {Broadcast Cooperation};
\end{scope}

% lines from each level 1 node to every one of its "children"
\foreach \value in {1,2,3}
  \draw[->] (c1.195) |- (c1\value.west);

\foreach \value in {1,2}
  \draw[->] (c2.195) |- (c2\value.west);

\foreach \value in {1,2,3}
  \draw[->] (c3.195) |- (c3\value.west);
\end{tikzpicture}

\end{document}

输出

相关内容