1

The questions below arose after trying to use code from an answer to the question at TikZ-tree: edge-alignment in horizontal org-chart

Question 1: As you can see I changed paper format to use B (11x17) and the picture scaled accordingly including text inside the boxes. As smaller text size is required, I tried changing 12pt to 10pt. Instead of changing text size, it changed width of the boxes. What is required in the code to use smaller text without changing tree layout?

Question 2: Why does new line \\ work in the teammate and subordinate styles, but not in Supervisor node? Does it need its own style?

Question 3: Is it possible to keep the units uniform, i.e. not use pt, cm, ex, em but limit the use of units to the minimum required?

Question 4: I could not find Tikz package and trees library at CTAN. Where can I find documentation?

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[landscape,paper=ansibpaper]{geometry}
\usepackage{tikz}
\usetikzlibrary{trees}
\tikzstyle{every node}=[draw=black,thick,anchor=west, minimum height=2.5em]

\begin{document}

\begin{figure}[!htb]
\resizebox{\linewidth}{!}{

\begin{tikzpicture}[
teammate/.style={text centered, text width=3cm, fill=gray!10},
subordinate/.style={%
    grow=down, xshift=0em,
    text centered, text width=3cm,
    edge from parent path={(\tikzparentnode.225) |- (\tikzchildnode.west)}},
    level1/.style ={level distance=8ex},
    level2/.style ={level distance=16ex},
    level3/.style ={level distance=24ex},
    level4/.style ={level distance=32ex},
    level5/.style ={level distance=40ex},
    level 1/.style={sibling distance=10em}]
    % Supervisor
    \node[anchor=south]{Supervisor \\ Supervisory position}
    [edge from parent fork down]

    % Teammate and Subordinates
    child{node [teammate] {Teammate1}
        child[subordinate,level1] {node {Subordinate\\Position1\\Location1}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Subordinate3}}
        child[subordinate,level4] {node {Subordinate4\\Position4\\Location4}}
        child[subordinate,level5] {node {Subordinate5\\Position5\\Location5}}}
    %
    child{node [teammate] {Teammate2}
        child[subordinate,level1] {node {Subordinate1}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Third\\Teammate}}
        child[subordinate,level4] {node {Longtext-\\teammate}}}
    %
    child{node [teammate] {Teammate3}
        child[subordinate,level1] {node {Subordinate\\two lines}}
        child[subordinate,level2] {node {Subordinate2}}     
        child[subordinate,level3] {node {Subordinate3}}}
    %
    child{node [teammate] {Teammate4}
        child[subordinate,level1] {node {Subordinate1}}
        child[subordinate,level2] {node {Subordinate2}}}
    %
    child{node [teammate] {Teammate5}
        child[subordinate,level1] {node {First\\Subordinate}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Third\\Teammate}}
        child[subordinate,level4] {node {Longtext-\\teammate}}};
\end{tikzpicture}}
\caption{This is an org chart}
\end{figure}

\end{document}
4
  • Documentation: starts p 475 sec 53 of the tikz manual. The libraries don't (generally) have separate documentation. Change measures such as ex to something independent of font size if you want only the text size to change. cm is obviously OK but ex, em etc. all dependent on the font. (Roughly speaking... generally... usually...) – cfr Feb 5 '14 at 2:14
  • Add text width=4cm, text centered to the supervisor node to get the line break. – cfr Feb 5 '14 at 2:21
  • Re. question 4, see ctan.org/pkg/pgf – John Kormylo Feb 5 '14 at 4:55
  • @cfr This works great, but then supervisor's box overlaps its connecting lines and adding level distance=2.5cm to any stile does not seem to add any distance. – ajeh Feb 5 '14 at 15:38
3

The supervisor node is missing the width and alignment style. The other nodes already have text centered, text width=3cm as style, which allows line breaking.

Suggestion: start with a basic style, and inherit this style, add or change settings when needed.

\begin{tikzpicture}[
  position/.style    = {text centered, text width=3cm},
  supervisor/.style  = {position, text width=4cm, anchor=south},
  teammate/.style    = {position, fill=gray!10},
  subordinate/.style = {position,
      grow=down, xshift=0em,
      ...

That was Q1, regarding Q1 and Q3: use styles as much as you can, Q4: PGF on CTAN or SourceForge. (Tipp: the actual name of the package is PGF, TikZ is just the frontend part).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.