&
我怎样才能在条件中包含一个逻辑,where
以便条件不匹配只有一个孩子的父母 4-8,以便他们正常地南北生长?即将条件更改为类似以下内容:where n children=0 & parent.n children>1
平均能量损失
\documentclass[border=1cm]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={
draw=black,align=center,parent anchor=south, child anchor=north,
edge path={
\noexpand\path[\forestoption{edge}]
(!u.parent anchor) -- +(0,-0.125in) -|
(.child anchor)\forestoption{edge label};
},
where n children=0{
child anchor=west,
for parent={
parent anchor=south,
grow'=east,calign=child edge
}
}{}
}
[Root
[Parent 1
[,phantom]
[Child 1]
[Child 2]
[Child 3]
]
[Parent 2
[Child 1
[,phantom]
[Child 1]
[Child 2]
]
]
[Parent 3
[,phantom]
[Child 1]
[Child 2]
[Child 3]
]
[Parent 4
[Only Child 1]
]
[Parent 5
[Only Child 1]
]
[Parent 6
[Only Child 1]
]
[Parent 7
[Only Child 1]
]
[Parent 8
[Only Child 1]
]
]
\end{forest}
\end{document}
答案1
我认为这是解决你的问题的方法:
\documentclass[border=1cm]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={
draw=black,align=center,parent anchor=south, child anchor=north,
edge path={
\noexpand\path[\forestoption{edge}]
(!u.parent anchor) -- +(0,-0.125in) -|
(.child anchor)\forestoption{edge label};
},
if={level>0}{% skip root (reason: root has no parent)
if={n_children==0 && n_children("!parent")>1}{% changed to if and added additional condition
child anchor=west,
for parent={
parent anchor=south,
grow'=east,calign=child edge
}
}{}
}{}
}
[Root
[Parent 1
[,phantom]
[Child 1]
[Child 2]
[Child 3]
]
[Parent 2
[Child 1
[,phantom]
[Child 1]
[Child 2]
]
]
[Parent 3
[,phantom]
[Child 1]
[Child 2]
[Child 3]
]
[Parent 4
[Only Child 1]
]
[Parent 5
[Only Child 1]
]
[Parent 6
[Only Child 1]
]
[Parent 7
[Only Child 1]
]
[Parent 8
[Only Child 1]
]
]
\end{forest}
\end{document}