这似乎是一个基本问题,但我想对于那些刚开始学习森林的人来说,使用工作示例很重要这个问题(通常看起来像这里的图 2)。我希望父级的第一个箭头看起来像图 1 中所示。我已经尝试了一段时间,但还没有弄明白。我还认为如果我在这里问的话也会对其他人有益。我已使用提供的链接中的代码作为基准。
编辑:我编辑了第一个 MWE,并修改了链接问题中的 MWE,以便更清晰。问题是,按照图 2 中的样式,当子级“拉直箭头”时,此图中的子级增加到十列。来自父级的箭头开始穿过其中一些。
\documentclass{article}
\usepackage{forest}
\usetikzlibrary{shadows,arrows.meta}
\tikzset{parent/.style={align=center,text width=2cm,fill=green!20,rounded corners=2pt},
child/.style={align=center,text width=2.8cm,fill=green!50,rounded corners=6pt},
grandchild/.style={fill=pink!50,text width=2.3cm}
}
\begin{document}
\begin{forest}
for tree={%
thick,
drop shadow,
l sep=0.6cm,
s sep=0.8cm,
node options={draw,font=\sffamily},
edge={semithick,-Latex},
where level=0{parent}{},
where level=1{
minimum height=1cm,
child,
parent anchor=south west,
tier=p,
l sep=0.25cm,
for descendants={%
grandchild,
minimum height=0.6cm,
anchor=150,
edge path={
\noexpand\path[\forestoption{edge}]
(!to tier=p.parent anchor) |-(.child anchor)\forestoption{edge label};
},
}
}{},
}
[Forest
[Straighten
[
[
[ ]
]
]
]
[The
[
[
[
[ ]
]
]
]
]
[Arrows
[
[
[
[
[]
]
]
]
]
]
]
\end{forest}
\end{document}
答案1
这种结构的例子已经很多了。以下内容改编自https://tex.stackexchange.com/a/299500/,其中可以找到解释性说明。
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usepackage[T1]{fontenc}
\tikzset{%
parent/.style={align=center,text width=3cm,rounded corners=3pt},
child/.style={align=center,text width=3cm,rounded corners=3pt}
}
\begin{document}
\begin{forest}
for tree={
% edge+={->},% uncomment for arrows
draw,
rounded corners,
node options={align=center,},
text width=2.7cm,
},
where level=0{%
parent anchor=children,
}{%
folder,
grow'=0,
if level=1{% this changes the edges from level 0 to nodes at level 1
before typesetting nodes={child anchor=north},
edge path'={(!u.parent anchor) -- ++(0,-5pt) -| (.child anchor)},
}{},
}
[LMS, fill=gray!25, parent
[Funktionale \\Anforderungen, for tree={fill=brown!25, child}
[Lerninhalte organisieren]
[Lerninhalte erstellen]
[Lerninhalte abfragen]
[Kommunikation]
[Benutzerkonten\-führung]
[Steuerungs\-funktionen]
]
[Nicht-Funktionale Anforderungen, for tree={fill=red!25,child}, calign with current edge
[Zuverl{\"a}ssig\-keit]
[Skalierbar\-keit und Effizienz]
[Benutzer\-freundlich\-keit]
[Portierbarkeit]
[Datenschutz / Informationssicherheit]
[Erweiterbar\-keit]
[Anpassbarkeit]
]
[Technische Rahmen\-bedinungen, for tree={fill=blue!25, child}
[System\-architektur]
[Software\-kriterien]
[Schnittstellen]
[Wartung und Support
[Support\-leistungen]
[Software-Pflege]
]
]
]
]
\end{forest}
\end{document}
编辑
为了解决编辑后的问题,获得所需效果的一种方法是设置parent anchor=center
根节点并使覆盖节点的边缘部分不可见。您可以background
使用background
库将它们放在图层上。或者您可以只使用“blend mode=lighten”。例如,
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usepackage[T1]{fontenc}
\tikzset{%
parent/.style={align=center,text width=3cm,rounded corners=3pt},
child/.style={align=center,text width=3cm,rounded corners=3pt}
}
\begin{document}
\begin{forest}
for tree={
% forked edges,
draw,
rounded corners,
node options={align=center,},
text width=2.7cm,
},
where level=0{%
parent anchor=center,
}{%
folder,
grow'=0,
if level=1{%
before typesetting nodes={child anchor=north},
edge path'={(!u.parent anchor) -| (.child anchor)},
edge+={blend mode=lighten},
}{},
}
[LMS, fill=gray!25, parent
[Funktionale \\Anforderungen, for tree={fill=brown!25, child}
[Lerninhalte organisieren]
[Lerninhalte erstellen]
[Lerninhalte abfragen]
[Kommunikation]
[Benutzerkonten\-führung]
[Steuerungs\-funktionen]
]
[Nicht-Funktionale Anforderungen, for tree={fill=red!25,child}, calign with current edge
[Zuverl{\"a}ssig\-keit]
[Skalierbar\-keit und Effizienz]
[Benutzer\-freundlich\-keit]
[Portierbarkeit]
[Datenschutz / Informationssicherheit]
[Erweiterbar\-keit]
[Anpassbarkeit]
]
[Technische Rahmen\-bedinungen, for tree={fill=blue!25, child}
[System\-architektur]
[Software\-kriterien]
[Schnittstellen]
[Wartung und Support
[Support\-leistungen]
[Software-Pflege]
]
]
]
]
\end{forest}
\end{document}
如果边缘比节点浅而不是深,blend mode=darken
则使用。