4

How can I align the nodes of the following tikz organigram?

\documentclass[10pt,letterpaper]{article}
\usepackage[margin=0.5cm, hmargin=0.5cm,vmargin=0.5cm]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{trees}
\begin{document}
\begin{center}
\begin{tikzpicture}[auto, node distance = 1cm, thick,
every node/.style = {rectangle, font = \sffamily, white,  
top color = blue!90!black, bottom color = blue!60!black,
text width = 3.5cm, align = center, minimum height = 1cm}]
\node (MAN) {\textbf{Adam Smith}\\CEO};
\node (PROD) [below left = 5cm of MAN] {\textbf{John Doe}};
\node (FIN)     [below = 3cm of MAN]  {\textbf{Steve Sanders}};
\node (RRHH) [below right = 5cm of MAN] {\textbf{Mike Donovan}};
\draw [blue,thick]
 (MAN) -- (FIN)
 (MAN) -| (PROD)
 (MAN) -| (RRHH);
 \end{tikzpicture}
\end{center}
\end{document}

I tried to modify the node distance and the node position but they never align properly, the position is never at the same level and the separation between the levels and the nodes is very wide.

Thanks in advance for your time!

3 Answers 3

3

Although you are loading the trees library, you are not formatting the diagram as a tree. However, doing so would avoid the need to position everything manually and draw the lines in separately.

I'm especially fond of Forest, a TikZ-based package for drawing trees, but you could also do this with the standard trees library or tikz-qtree or whatever.

Here's an annotated example:

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[edges]{forest}% load the edges library so we can use forked edges for the tree
\begin{document}
\begin{forest}
  for tree={% apply to entire tree
    edge={thick, draw=blue},% lines blue and thick
    % TikZ keys will be passed through so we can use all the usual styling stuff
    font=\sffamily\bfseries,% default is bold
    text=white,% white text
    top color=blue!90!black,
    bottom color=blue!60!black,
    text width=35mm,
    text centered,
    minimum height=10mm,
    l sep'=20mm,% spread out the levels a bit
    s sep'=10mm,% spread out the siblings a bit
  },
  forked edges,% lines should be squared off: down-acroos-down rather than the default which is as-the-eagle-flies
  % tree specification - notice how concisely the tree can be specified ...
  [Adam Smith\\\textmd{CEO}% override bold default for second line
    [John Doe]
    [Steve Sanders]
    [Mike Donovan]
  ]
\end{forest}
\end{document}

Forest version

5

Slightly simplified solution of Emma:

  • distances between nodes is controlled with common option node distance (selected is node distance = 1cm and 1.5cm)
  • option auto is deleted
  • for text color is used correct syntax (text=white)
  • boldface text is defined globally, exception for normal text for "CEO" is determined localy by \normalfont

Complete MWE is:

\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
    node distance = 1cm and 1.5cm,
every node/.style = {rectangle, font=\sffamily\bfseries, text=white,
                     top color=blue!90!black, bottom color=blue!60!black,
                     text width=3.5cm, align = center, minimum height = 1cm}
                     ]
\node (MAN)     {Adam Smith\\  \normalfont CEO};
\node (PROD) [below left = of MAN] {John Doe};
\node (FIN)  [below      = of MAN] {Steve Sanders};
\node (RRHH) [below right= of MAN] {Mike Donovan};
%
\draw [blue,thick]  (MAN) -- (FIN)
                    (MAN) -| (PROD)
                    (MAN) -| (RRHH);
    \end{tikzpicture}
\end{document}

and obtained organigramm is:

enter image description here

5

You can use two coordinates in below left, etc., to specify separate offsets for below and left:

\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[auto, node distance = 1cm, thick,
every node/.style = {rectangle, font = \sffamily, white,
top color = blue!90!black, bottom color = blue!60!black,
text width = 3.5cm, align = center, minimum height = 1cm}]
\node (MAN) {\textbf{Adam Smith}\\CEO};
\node (PROD) [below left = 1cm and 2cm of MAN] {\textbf{John Doe}};
\node (FIN)  [below = 1cm of MAN]  {\textbf{Steve Sanders}};
\node (RRHH) [below right = 1cm and 2cm of MAN] {\textbf{Mike Donovan}};
\draw [blue,thick]
 (MAN) -- (FIN)
 (MAN) -| (PROD)
 (MAN) -| (RRHH);
\end{tikzpicture}
\end{document}

enter image description here

It is also worth noting that by default below left etc. specify the space between the node borders. If you want better alignment in a large picture with differently sized nodes you might want to use the option on grid, which makes the distances specify the space between the node centers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .