更改森林中空節點的大小

更改森林中空節點的大小

我想設定如下圖:

在此輸入影像描述

下面的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}

然而,向左的弧沒有直角:

在此輸入影像描述

現在的問題是:我是否必須將\struts 添加到所有empty nodes 中,還是有更好的方法來表示empty nodes 與右側的姐妹具有相同的高度?

答案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}

在此輸入影像描述

相關內容