[Tex/LaTex] Organigram in Latex. Vertical distance between nodes

nodesspacingtikz-trees

I want to draw a organizational structure in form of an organigram. I found this solution and tried to adapt it. The code:

\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}

The result is

The result

As you can see, the vertical distance between boxes is ugly because I have some boxes with more lines than the respective sibling. Is there something I can do to get at least the same distance for all boxes under one parent?

Best Answer

You can use the node distance key as follows (change in 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}

output

Related Question