3

I am trying to create an organizational chart using folder option of forest package, please see the example below. However, one of the columns in the chart only has one node in it (Library), and I would like to utilize the available space underneath it by putting nodes from the next column (Provost Office) in both directions. I included a MWE below.

\documentclass[border=20pt,tikz]{standalone}
\usepackage[edges]{forest}

\forestset{
  orgchart/.style={
    for tree={edge+=thick, align=center,minimum width=15em,rounded corners},
    where level>=1{folder, grow'=0}{for children=forked edge},
    where level=3{}{draw}
  },
}

\newcommand{\chartname}[1] {    \textbf{#1}}

\begin{document}

\begin{forest}
  % forest preamble: determine layout and format of tree
  orgchart
  [{\chartname{The Boss}\\Provost and \\ Senior Vice President for Academic Affairs},fill=red!30
    [\chartname{Colleges},for tree={fill=green!20},for descendants={minimum height=4em},thick
      [{Dean,\\College of Business}]
      [{Dean,\\College of Journalism}]
      [{Dean,\\College of Arts and Sciences}]
      [{Dean, College of Engineering}]
    ]
    [\chartname{Library},for tree={fill=cyan!20},for descendants={minimum height=4em},thick
      [{Dean,\\University Libraries}]
    ]
    [\chartname{Provost Office},for tree={fill=black!20},for descendants={minimum height=4em},thick
      [{Vice Provost for\\ Faculty Affairs}]
      [{Vice Provost for\\Global Affairs}]
      [{Vice Provost for\\Undergraduate Education}]
      [{Vice Provost for\\Graduate Education}]
      [{Associate Provost\\ for Enrollment Management },fill=black!12]
      [{Assistant Provost for\\Academic Personnel},fill=black!7]
    ]
  ]
\end{forest}
\end{document}

This code gives the following result: Result of the Code

I would like the get a chart as below: Chart with nodes going both directions

Is there any way it can be done? Thank you!

6

This is certainly not a full-fledged answer, mainly for my own curiosity. If Sašo or cfr show up I can delete this. I added a folder' style in which, after the second sibling, every other node gets shifted. With where level>=1{if n=3{folder'}{folder}, we switch to this style in the 3rd branch. I strongly suspect that one can replace the hardcoded xshift by something more elegant, but my knowledge of forest is not deep enough to know what it is.

\documentclass[border=20pt,tikz]{standalone}
\usepackage[edges]{forest}

\forestset{
  orgchart/.style={
    for tree={edge+=thick, align=center,minimum width=15em,rounded corners},
    where level>=1{if n=3{folder'}{folder},%<- added: switch for 3rd branch
    grow'=0}{for children=forked edge},
    where level=3{}{draw}
  },
}


\forestset{
folder'/.style={
parent anchor=-children last, anchor=parent first, calign=child,
calign primary child=1,
for children={child anchor=-parent,% <- "-parent" instead of "parent"
xshift={-(n()>1)*isodd(n())*16.5em},%<- main change
anchor=parent first, edge={rotate/.option=!parent.grow}, edge path'/.expanded={
([xshift={\forestregister{folder indent}}]!u.parent anchor) |- () },
},
after packing node={
if n children=0{}{
tempdiml=l_sep()-l("!1"), tempdims={-abs(max_s("","")-min_s("",""))-s_sep()}, 
for children={
l+=tempdiml,
s+=tempdims()*(reversed()-0.5)*2, },
}, },
}}
\newcommand{\chartname}[1]{\textbf{#1}}

\begin{document}

\begin{forest}
  % forest preamble: determine layout and format of tree
  orgchart
  [{\chartname{The Boss}\\Provost and \\ Senior Vice President for Academic Affairs},fill=red!30
    [\chartname{Colleges},for tree={fill=green!20},for descendants={minimum height=4em},thick
      [{Dean,\\College of Business}]
      [{Dean,\\College of Journalism}]
      [{Dean,\\College of Arts and Sciences}]
      [{Dean, College of Engineering}]
    ]
    [\chartname{Library},for tree={fill=cyan!20},for descendants={minimum height=4em},thick
      [{Dean,\\University Libraries}]
    ]
    [\chartname{Provost Office},for tree={fill=black!20},
        for tree={if={isodd(s())}{grow'=180}{grow'=0}},
        for descendants={minimum height=4em},thick,
      [{Vice Provost for\\ Faculty Affairs}]
      [{Vice Provost for\\Global Affairs}]
      [{Vice Provost for\\Undergraduate Education}]
      [{Vice Provost for\\Graduate Education}]
      [{Associate Provost\\ for Enrollment Management },fill=black!12]
      [{Assistant Provost for\\Academic Personnel},fill=black!7]
    ]
  ]
\end{forest}
\end{document}

enter image description here

1
  • This is beautiful. I have a lot to learn from this code. Thank you! – andant Apr 3 '20 at 17:15
5

One way is to draw the two nodes that need to change position manually, and set their position relative to nodes in the tree that you identify using the name property.

MWE:

\documentclass[border=20pt,tikz]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{positioning}

\tikzset{manualpos/.style={
    draw,
    thick,
    align=center,
    minimum width=15em,
    minimum height=4em,
    rounded corners
    }
}

\forestset{
  orgchart/.style={
    for tree={edge+=thick, align=center,minimum width=15em,rounded corners},
    where level>=1{folder, grow'=0}{for children=forked edge},
    where level=3{}{draw}
  },
}

\newcommand{\chartname}[1] {    \textbf{#1}}

\begin{document}

\begin{forest}
  % forest preamble: determine layout and format of tree
  orgchart
  [{\chartname{The Boss}\\Provost and \\ Senior Vice President for Academic Affairs},fill=red!30
    [\chartname{Colleges},for tree={fill=green!20},for descendants={minimum height=4em},thick
      [{Dean,\\College of Business}]
      [{Dean,\\College of Journalism}]
      [{Dean,\\College of Arts and Sciences}]
      [{Dean, College of Engineering}]
    ]
    [\chartname{Library},for tree={fill=cyan!20},for descendants={minimum height=4em},thick
      [{Dean,\\University Libraries}]
    ]
    [\chartname{Provost Office},for tree={fill=black!20},for descendants={minimum height=4em},thick
      [{Vice Provost for\\ Faculty Affairs}]
      [{Vice Provost for\\Global Affairs},name=global affairs]
      [{Vice Provost for\\Graduate Education},name=graduate education]
      [{Assistant Provost for\\Academic Personnel},fill=black!7]
    ]
  ]
  \node[manualpos,fill=black!20,left=6mm of global affairs] (undergraduate education) {Vice Provost for\\Undergraduate Education};
  \draw (undergraduate education) -- (global affairs);
  \node[manualpos,fill=black!12,left=6mm of graduate education] (enrollment management){Associate Provost\\for Enrollment Management};
  \draw (enrollment management) -- (graduate education);
\end{forest}
\end{document}

Result:

enter image description here

1
  • Thank you! This manual solution works great for what I need. – andant Apr 3 '20 at 16:40

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.