使用 forest.sty 的组织结构图,节点双向流动

使用 forest.sty 的组织结构图,节点双向流动

我正在尝试使用 Forest 包的文件夹选项创建组织结构图,请参见下面的示例。但是,图表中的其中一列只有一个节点(图书馆),我想通过在两个方向上放置下一列(教务长办公室)的节点来利用其下方的可用空间。我在下面包含了一个 MWE。

\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}

此代码给出以下结果: 代码结果

我想要得到如下的图表: 带有双向节点的图表

有什么办法吗?谢谢!

答案1

这当然不是一个完整的答案,主要是出于我自己的好奇心。如果 Sašo 或 cfr 出现,我可以删除它。我添加了一种folder'样式,在第二个兄弟节点之后,每个其他节点都会移动。where level>=1{if n=3{folder'}{folder},我们在第三个分支中切换到这种样式。我强烈怀疑有人可以用xshift更优雅的东西代替硬编码,但我对它的了解forest还不够深入,不知道它是什么。

\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}

在此处输入图片描述

答案2

一种方法是绘制需要手动改变位置的两个节点,并设置它们相对于使用属性标识的树中的节点的位置name

梅威瑟:

\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}

结果:

在此处输入图片描述

相关内容