我想設定如下圖:
下面的forest
程式碼幾乎可以做到這一點:
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={fit=band,parent anchor=south,child anchor=north}
[ForceP
[]
[Force$'$
[Force$^0$]
[TopP
[]
[Top$'$
[Top$^0$]
[FocP
[]
[Foc$'$
[Foc$^0$]
[TopP
[]
[Top$'$
[Top$^0$]
[FinP
[]
[Fin$'$
[Fin$^0$]
[IP/AgrSP]]]]]]]]]]]
\end{forest}
\end{document}
然而,向左的弧沒有直角:
現在的問題是:我是否必須將\strut
s 添加到所有empty node
s 中,還是有更好的方法來表示empty node
s 與右側的姐妹具有相同的高度?
答案1
sn edges
這是另一種方法,當我也將樣式添加到樹中時,它對我來說看起來更好。這不是使用nice empty nodes
設定shape
為 的技巧coordinate
,而是為空節點(只是一個X
)創建虛擬內容,並為樹中的所有節點使用標準文字高度以保持對齊。
\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest,calc}
\begin{document}
\newlength\mytextheight
\settototalheight{\mytextheight}{XpX$^0$X$'$}
\begin{forest}
delay={
where content={}{
content={\phantom{X}}
}{},
},
for tree={
text height=\mytextheight,
fit=band,
parent anchor=south,
child anchor=north,
}
[ForceP
[]
[Force$'$
[Force$^0$]
[TopP
[]
[Top$'$
[Top$^0$]
[FocP
[]
[Foc$'$
[Foc$^0$]
[TopP
[]
[Top$'$
[Top$^0$]
[FinP
[]
[Fin$'$
[Fin$^0$]
[IP/AgrSP]
]
]
]
]
]
]
]
]
]
]
\end{forest}
\end{document}
答案2
您可以nice empty nodes
依照手冊第 52 頁定義樣式forest
。
\documentclass{article}
\usepackage{forest}
\forestset{
nice empty nodes/.style={
for tree={calign=fixed edge angles},
delay={where content={}{for parent={for children={anchor=north}}}{}}
}}
\begin{document}
\begin{forest}
for tree={fit=band}
[ForceP, nice empty nodes
[]
[Force$'$
[Force$^0$]
[TopP
[]
[Top$'$
[Top$^0$]
[FocP
[]
[Foc$'$
[Foc$^0$]
[TopP
[]
[Top$'$
[Top$^0$]
[FinP
[]
[Fin$'$
[Fin$^0$]
[IP/AgrSP]]]]]]]]]]]
\end{forest}
\end{document}