\documentclass{standalone}
\usepackage{forest}
\usepackage{rotating}
\begin{document}
\centering
\begin{forest}
for tree={
if level=0{
align=center,
l sep=20mm,
}{%
align={@{}C{1.5em}@{}},
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-5mm) -| (.child anchor)\forestoption{edge label};
},
},
draw,
font=\sffamily\bfseries,
parent anchor=south,
child anchor=north,
l sep=10mm,
edge={thick, rounded corners=1pt},
thick,
inner color=gray!5,
outer color=gray!20,
rounded corners=2pt,
%drop shadow,
fzr/.style={
alias=fzr,
align=center,
child anchor=west,
fill=green!25,
edge path={
\noexpand\path[\forestoption{edge}]
([yshift=-1em]!u.parent anchor) -- (.child anchor)\forestoption{edge label};
},
},
}
[manager, alias=master, align=center
% [expatriate,fzr]
[\rotatebox{90}{bureau}]
[\rotatebox{90}{production}
[\rotatebox{90}{line}]
]
[\rotatebox{90}{finance}]
[\rotatebox{90}{quality},align=center
%[quality supervisor,fzr]
[\rotatebox{90}{laboratory}]
[\rotatebox{90}{review}]
]
[\rotatebox{90}{supply}
[\rotatebox{90}{material}]
[\rotatebox{90}{\parbox{2.5cm}{Semi-finished\\ products}}]
[\rotatebox{90}{\parbox{2.5cm}{Finished\\ product}}]
]
]
\node [draw,font=\sffamily\bfseries,thick,fill=green!25,rounded corners=2pt,xshift=25mm,] (fuzeren) [yshift=-1.3em,] {expatriate};
\path [draw,thick] ([yshift=-.5em]!master.south) -- (fuzeren);
\end{forest}
\end{document}
它看起来像这样:
事实上,我修改了别人的代码,但我并不真正理解代码中的所有内容。我想要的图表是:
- “经理”与“质量”对齐,“供应”与“半成品”对齐(我已经让“质量”对齐=中心。我不知道为什么它与经理不一致)。
- 连接线转弯处不要有圆角,以保证交叉处平直。
- 它应该为“外籍人士”留出一些位置,以便不触及水平线。
- 各层框架应以上边框对齐。
无论如何,有人能提供解决方案来帮助我实现我想要的树形图吗?
答案1
如果没有可运行的代码,也不知道在哪里可以找到缺少内容的原始源代码,那么就只能从头开始。
使用edges
的库forked edges
。让 Forest 进行轮换。让 Forest 安置外籍人员。这样代码就更简单、更干净、更直接了。
如果你不明白代码中的某些内容,查阅手册。如果你不明白解释,请询问。如果你使用别人的代码,归因于。人们都有名字。他们不是无名之辈。
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{shadows.blur}
\begin{document}
\begin{forest}
forked edges,
for tree={
edge+={thick},
inner color=gray!5,
outer color=gray!20,
rounded corners=2pt,
draw,
thick,
tier/.option=level,
align=center,
font=\sffamily,
blur shadow,
},
where level<=1{}{
rotate=90,
anchor=east,
},
[manager
[, coordinate, calign with current
[bureau]
[production
[line]
]
[finance]
[quality, calign with current
[laboratory]
[review]
]
[supply
[material]
[Semi-finished\\products, calign with current]
[Finished\\product]
]
]
[expatriate, inner color=green!10, outer color=green!25, child anchor=west, edge path'={(!u.parent anchor) -| (.child anchor)}, before drawing tree={y'+=7.5pt} ]
]
\end{forest}
\end{document}