\documentclass[border=3pt]{standalone}
\usepackage{forest}
\usetikzlibrary{shadows,arrows.meta}
\tikzset{parent/.style={align=center,text width=3cm,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=1.5cm}
}
\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{minimum height=1cm,parent}{},
where level=1{
minimum height=0.8cm,
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};
},
}
}{},
}
[developmental %\hspace{1em}\hspace{1em}
[two parts
[cognition
[cognition developmental
]
]
]
[four part
[social
[physical
[action
[language
]
]
]
]
]
]
\end{forest}
\end{document}
答案1
罪魁祸首是anchor=150
中的键where level=1
。为什么它会移动左分支中最低的节点,而不移动其他节点?因为最低节点的高度与其他孙节点的高度不同。因此, 的anchor=150
水平位置(相对于节点中心)与所有其他节点都不同,而其他所有节点的高度都相同。因此,相对位置发生了偏移。所以你可能想删除这个键。
\documentclass[border=3pt]{standalone}
\usepackage{forest}
\usetikzlibrary{shadows,arrows.meta}
\tikzset{parent/.style={align=center,text width=3cm,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=1.5cm}
}
\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{minimum height=1cm,parent}{},
where level=1{
minimum height=0.8cm,
child,
parent anchor=south west,
tier=p,
l sep=0.25cm,
for descendants={%
grandchild,
minimum height=0.6cm,
edge path={
\noexpand\path[\forestoption{edge}]
(!to tier=p.parent anchor) |-(.child anchor)\forestoption{edge label};
},
}
}{},
}
[developmental
[two parts
[cognition
[cognition developmental]
]
]
[four part
[social
[physical
[action
[language
]
]
]
]
]
]
\end{forest}
\end{document}