9

How can I draw WBS diagrams (Work breakdown structures) in LaTeX?

I need to draw in LaTeX things like:

enter image description here

I've searched on the Internet a lot but I've found nothing.

1

2 Answers 2

12

A starting point:

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


\tikzset{
every node/.style={draw,text width=2cm,drop shadow},
style1/.style= {rectangle, rounded corners=2pt, thin,align=center,fill=green!30},
style2/.style= {rectangle, rounded corners=6pt, thin,align=center,fill=green!60},
style3/.style= {rectangle,thin,align=left,fill=pink!60}
}

\begin{document}


\begin{tikzpicture}[
remember picture,
level 1/.style={sibling distance=40mm},
edge from parent/.style={->,draw},
>=latex]

% the initial tree ("root" and "text nodes")
\node[style1] {root}
child {node[style2] (c1) {text}}
child {node[style2] (c2) {text}}
child {node[style2] (c3) {text}};

% the nodes below each of the "text" nodes
\node [style3,below of = c1,xshift=15pt] (c11) {A};
\node [style3,below of = c11] (c12) {A};
\node [style3,below of = c12] (c13) {A};

\node [style3,below of = c2,xshift=15pt] (c21) {B};
\node [style3,below of = c21] (c22) {B};
\node [style3,below of = c22] (c23) {B};
\node [style3,below of = c23] (c24) {B};

\node [style3,below of = c3,xshift=15pt] (c31) {C};
\node [style3,below of = c31] (c32) {C};
\node [style3,below of = c32] (c33) {C};
\node [style3,below of = c33] (c34) {C};
\node [style3,below of = c34] (c35) {C};

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

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

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

\end{document}

enter image description here

Stefan Kottwitz has made some modifications to my code and has also added some real text to the nodes; the result can also be seen in texample.net:

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

\tikzset{
  basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
  root/.style   = {basic, rounded corners=2pt, thin, align=center,
                   fill=green!30},
  level 2/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
  level 3/.style = {basic, thin, align=left, fill=pink!60, text width=6.5em}
}

\begin{document}

\begin{tikzpicture}[
  level 1/.style={sibling distance=40mm},
  edge from parent/.style={->,draw},
  >=latex]

% root of the the initial tree, level 1
\node[root] {Drawing diagrams}
% The first level, as children of the initial tree
  child {node[level 2] (c1) {Defining node and arrow styles}}
  child {node[level 2] (c2) {Positioning the nodes}}
  child {node[level 2] (c3) {Drawing arrows between nodes}};

% The second level, relatively positioned nodes
\begin{scope}[every node/.style={level 3}]
\node [below of = c1, xshift=15pt] (c11) {Setting shape};
\node [below of = c11] (c12) {Choosing color};
\node [below of = c12] (c13) {Adding shading};

\node [below of = c2, xshift=15pt] (c21) {Using a Matrix};
\node [below of = c21] (c22) {Relatively};
\node [below of = c22] (c23) {Absolutely};
\node [below of = c23] (c24) {Using overlays};

\node [below of = c3, xshift=15pt] (c31) {Default arrows};
\node [below of = c31] (c32) {Arrow library};
\node [below of = c32] (c33) {Resizing tips};
\node [below of = c33] (c34) {Shortening};
\node [below of = c34] (c35) {Bending};
\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,...,4}
  \draw[->] (c2.195) |- (c2\value.west);

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

\end{document}

An image of the resulting diagram:

enter image description here

4
  • See tex.stackexchange.com/questions/206971/….
    – cfr
    Commented Feb 23, 2015 at 23:34
  • 1
    I like it, but I wonder how to set the length of each box?
    – wayne
    Commented Jul 7, 2015 at 14:52
  • I keep getting 'Use of \@next doesn't match its definition' for \draw[->] (c1.195) |- (c1\value.west); :(
    – mirgee
    Commented Mar 1, 2019 at 17:57
  • What does 195 mean? How can you make the anchor closer to the level 2 boxes at the south west side?
    – BHamza
    Commented Apr 15, 2020 at 18:20
4

As an alternative to TikZ tree library, it's possible to use forest package. Which usually results in a less verbose code. Following solution is not perfect but it can give you an idea.

\documentclass{article}
\usepackage{forest}
\useforestlibrary{edges}

%\usepackage{tikz}
\usetikzlibrary{shadows}

\tikzset{
  basic/.style = {
    draw, text width=2cm, thin, align=center, 
    drop shadow, font=\sffamily
    },
  root/.style = {
    basic, rounded corners=2pt, 
    text width=2cm,
   fill=green!30},
  level 2/.style = {
    basic, rounded corners=6pt,
    fill=green!60, text width=8em},
  level 3/.style = {
    basic, 
    align=left, 
    fill=pink!60, text width=6.5em}
}

\begin{document}

\begin{forest}
[Drawing diagrams, root
    [Defining node and arrow styles, 
        level 2, for tree={grow'=0,  folder}, 
        for children={level 3},
        [Setting shape]
        [Choosing color]
        [Adding shading]]
    [Positioning\\ the nodes, 
        level 2, for tree={grow'=0,  folder}, 
        for children={level 3},
        [Using a Matrix]
        [Relatively]
        [Absolutely]
        [Using overlays]]
    [Drawing arrows\\ between nodes, 
        level 2, for tree={grow'=0,  folder}, 
        for children={level 3},
        [Default arrows]
        [Arrow library]
        [Resizing tips]
        [Shortening]
        [Bending]]]
\end{forest}

\end{document}

enter image description here

7
  • There are an awful lot of codes for this particular example already. I'm pretty sure there's already at least one Forest version. You could have saved yourself the trouble and copied that. (I think I've drawn this from scratch at least twice, but I can't remember if I used Forest once, twice or not myself at all.)
    – cfr
    Commented Dec 16, 2017 at 5:17
  • @cfr This is the main problem for tex.sx how to find something you know is there but don't remember where. ;)
    – Ignasi
    Commented Dec 16, 2017 at 9:03
  • I know. Sometimes I know I've answered a question, even - and still can't find it. In this case, though, the link in my comment on GM's answer includes two Forest codes for the diagram.
    – cfr
    Commented Dec 16, 2017 at 16:42
  • This answer should really be posted as an answer to the linked thread, as it would make a useful third addition. Your version uses the stuff from current Forest, which the answers there don't (too old).
    – cfr
    Commented Dec 16, 2017 at 16:46
  • How do you center the root node above the second one in the second level?
    – mirgee
    Commented Mar 1, 2019 at 18:45

You must log in to answer this question.

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