4

What is the easiest way to draw a tree like this. I am using pdflatex.

enter image description here

I tried with this, but it got missed up taken from source, i am having many issues such as the height of the fork is too much (how can i make it dynamic). (2) how can i control the horizontal spacing among children to avoid overlapping as i got down there.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{shadings}

\begin{document}

\begin{figure}[!htb]


\begin{tikzpicture}[
every node/.style={draw=black,thin, minimum height=1.5em},
    supervisor/.style={%
    align=center,
        edge from parent fork down,
        level distance=0.1cm,
        align=center,},
    area/.style={%
        text centered, text width=3cm,
        level distance=4cm,
        fill=gray!10,draw,
        -latex},
    method/.style={%
   thick,anchor=west, minimum height=2.5em,
        grow=down, xshift=-1.1cm, % Horizontal position of the child node
        text centered, text width=3cm,
        edge from parent path={(\tikzparentnode.205) |- (\tikzchildnode.west)},draw, -latex},
    level1/.style ={level distance=1.5cm},
    level2/.style ={level distance=3cm},
    level3/.style ={level distance=4.5cm},
    level4/.style ={level distance=6cm},
    level5/.style ={level distance=7.5cm},
    level 1/.style={sibling distance=4cm},
    level 1/.append style={level distance=4.5cm},
]
%   \draw[help lines] (0,0) grid (4,3);

    % Supervisor
    \node[anchor=south,supervisor,align=center]{Base}
    [edge from parent fork down]

    % Teammate and Subordinates
    child{
        node [area] {Attributable \\ Measurements}  
        [edge from parent fork down]  
             child{ 
             node [area] {Attributable \\ Measurements}
                    }
            child{  
                             node [area] {Attributable \\ Measurements}
                                    }
      }
    %
    child{node [area] {Teammate2\\Position2\\Location2}
        child[method,level1] {node {Subordinate1}}
        child[method,level2] {node {Subordinate2}}
        child[method,level3] {node {Third\\Teammate}}
        child[method,level4] {node {Longtext-\\area}}}; 
%\shade[shading=Mandelbrot set] (0,0) rectangle (5,5);
\end{tikzpicture}
\caption{This is an org chart}
\end{figure}
\end{document}

enter image description here Thank you.

  • What exactly is your question? From your picture, it looks like you are on a good path, the trees package is a good way to do it. A few pointers: using names level1 and level 1 as definitions is confusing at best. Put your style definitions into one logical block; append is used inside a scope, where you locally want to add to a prior definition. – Huang_d May 29 '17 at 21:45
  • Thank you for your reply. I am facing many issues such as the overlapping. How can i solve this issue (or make children spacing dynamic) and how can i control the height to make it look better. I updates the question. thank you. – Sari May 29 '17 at 21:54
  • If it is the first time that you create a tree, it might be worthwhile to go through the tutorial in chapter five of the pgf manual, ctan.org/pkg/pgf I am by no means an expert in trees; the level distance can be manually controlled by changing level 1/.style={level distance=2.5cm}, sibling distance by choosing a higher value for the sibling distance in level 1 again. – Huang_d May 29 '17 at 22:08
  • Forest can handle much of the layout automatically, although you may need to help it if it gets too complex. The edges library has a folder style which would handle the directory-style part of your tree. There are some examples on the site showing how to handle the switch of direction. Make sure you have version 2 and that you use an example based on the edges library. – cfr May 31 '17 at 2:01
  • tex.stackexchange.com/a/339891, tex.stackexchange.com/a/340528, tex.stackexchange.com/questions/337867/…. (Sorry, these are my answers because I could find them easily.) These are all basically the structure you want. – cfr May 31 '17 at 2:03
7

If your tree is like a family tree, you may consider to use a family tree drawing package like genealogytree.

There is no option to switch the growing direction, but all distances are computed automatically. The original picture could be drawn like this:

enter image description here

The code is the following:

\documentclass{article}
\usepackage{geometry}
\usepackage[templates]{genealogytree}
\usepackage{lmodern}

\begin{document}
\begin{figure}
\noindent\resizebox{\textwidth}{!}{
\begin{genealogypicture}[
  template=signpost,
  level distance=10mm,
  level size=8mm,
  node size=15mm,
  box={colback=white,sharp corners,fontupper=\sffamily},
  mark/.style={box={colback=blue!20}},
  edges={foreground={line width=1pt,red,-LaTeX,},background={line width=2pt,white}}
  ]
child{
  g{root}
  child{ g{l}
    child{ g{lx1}
      child{ g[mark]{lx11}
        c[mark]{lx111} c[mark]{lx112}
      }
      c[mark]{lx12} c[mark]{lx13} c[mark]{lx14}
    }
    child{ g{ll1}
      child{ g{ll11}
        c[mark]{ll111}
      }
      child{ g{ll12}
        c[mark]{ll121} c[mark]{ll122}
      }
    }
  }
  child{ g{r}
    child{ g{r1}
      child{ g{r11}
        c[mark]{r111} c[mark]{r112}
      }
      child{ g{r12}
        c[mark]{r121} c[mark]{r122}
      }
    }
  }
}
\end{genealogypicture}
}
\caption{This is an org chart}
\end{figure}
\end{document}
| improve this answer | |
  • Not exactly 'the original picture' but +1 for being able to use the package. (I'm not sure if you wrote it, but either way.) – cfr Jun 1 '17 at 2:25
2

Here's a method using an updated and tweaked version of dir tree switch forking, which I used in the answer I linked earlier.

A coordinate-shaped node is used to adjust for the fact that the switch in both growth direction and style occurs at level 2 for the left branch (or not at all), but at what would otherwise be level 1 for the right branch. The additional node makes it level 2 for both.

\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta}
\forestset{%
  dir tree switch forking/.style args={at #1}{%
    for tree={
      font=\sffamily,
      fit=rectangle,
    },
    where level=#1{
      for tree={
        folder,
        grow'=0,
      },
      delay={
        child anchor=north,
        !u.parent anchor=south,
        edge path'={(!u.parent anchor) -- ++(0,-\forestoption{fork sep}) -| (.child anchor)}
      },
    }{
      if={>On<{level}{#1}}{
        forked edge,
        parent anchor=children,
        child anchor=parent,
      }{},
    },
    before typesetting nodes={
      for tree={
        if content={}{
          coordinate,
          no edge,
          before packing={!u.l sep'=0pt},
          before computing xy={s/.option=!u.min x}
        }{
          content/.wrap value={\strut ##1},
        },
      },
      for nodewalk={filter={tree}{>On<{level}{#1}}}{align to centre},
    },
  },
  align to centre/.style={
    if={>Ow+P{n children}{isodd(#1)}}{
      for nodewalk/.process={Ow+nw{!r.n children}{(#1+1)/2}{{fake=r,n=#1}{calign with current edge}}},
    }{
      calign=edge midpoint,
    },
  },
}

\begin{document}
\begin{forest}
  area/.style={%
    fill=gray!10,draw,
  },
  method/.style={%
    thick,
    edge+={-Latex},
  },
  dir tree switch forking=at 2,
  for tree={
    draw,
    align=center,
    thin,
    minimum height=1.5em,
  },
  [Base
    [Attributable\\Measurements, for tree=area
      [Attributable\\Measurements
      ]
      [Attributable\\Measurements
      ]
    ]
    [Teammate2\\Position2\\Location2, area, for descendants=method
      [,coordinate
        [Subordinate1]
        [Subordinate2]
        [Third\\Teammate]
        [Longtext-\\area]
      ]
    ]
  ]
\end{forest}
\end{document}

forked tree with direction switch at different levels

| improve this answer | |

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.