漂亮的空節點被森林 2.0 破壞了?

漂亮的空節點被森林 2.0 破壞了?

我已經使用森林手冊中的“漂亮的空節點”樣式已有相當一段時間了。今天我更新了包,現在它拋出一個錯誤(儘管輸出似乎仍然有效)。最小的例子:

\documentclass{article}
\usepackage{forest}
\forestset{
nice empty nodes/.style={
    for tree={calign=fixed edge angles},
    delay={where content={}{shape=coordinate,for parent={
                for children={anchor=north}}}{}}
},
}
\begin{document}
\begin{forest}
    [{},nice empty nodes
    [b][
    [c]
    [
    [b] [a]
    ]
    ]
    ]
\end{forest}
\end{document}

錯誤:“打包森林錯誤:nodewalk 走到無效節點;堆疊:“,tree,tree,parent”。\end{forest}”

有人知道如何解決這個問題嗎?

答案1

正如@cfr 指出的那樣,

問題是節點遍歷已經發生了巨大的變化,無效的步驟現在預設會觸發錯誤。因為根是空的,所以它得到了很好的空節點處理,並且父節點失敗了,因為沒有父節點。

所以,是的,這是 定義中的一個錯誤nice empty nodes,所以感謝您發現它並指出它。我沒有註意到它,因為nice empty nodes文檔中的唯一示例沒有將樣式應用於根節點,因此文檔編譯得很好......

該解決方案實際上非常簡單(並將包含在即將發布的次要版本中),因為forest現在有步驟siblings

\documentclass{article}
\usepackage{forest}
\forestset{
nice empty nodes/.style={
    for tree={calign=fixed edge angles},
    delay={where content={}{shape=coordinate,for siblings={anchor=north}}{}}
},
}
\begin{document}
\begin{forest}
    [{},nice empty nodes
    [b][
    [c]
    [
    [b] [a]
    ]
    ]
    ]
\end{forest}
\end{document}

請注意,該for parent={for children={...}}習慣用法與 不完全相同for siblings={...},因為在這種情況下當前節點沒有被遍歷for siblings。在我們的例子中,這沒有什麼區別,因為當前節點獲得了座標形狀。要準確獲得(舊)for parent={for children={...}}行為,請說for preceding siblings={...},for current and following siblings={...}。我承諾for current and siblings在下一個小版本中包含密鑰......直到現在我才意識到在某種情況下擁有它是有意義的。

答案2

肯定是個錯誤?即使加載庫並在樹序言中linguistics使用官方也不起作用。nice empty nodes

這非常不優雅,但現在應該可以工作。問題是節點遍歷已經發生了巨大的變化,無效的步驟現在預設會觸發錯誤。因為根是空的,所以它得到nice empty nodes處理並for parent失敗,因為沒有父項。這希望僅針對此節點遍歷禁用它,而不是全域禁用它。但是,我確信有一種更有效的方法。

\documentclass[tikz]{standalone}
\usepackage{forest}
\forestset{%
  nice empty nodes/.style={%
    for tree={calign=fixed edge angles},
    delay={%
      where content={}{%
        shape=coordinate,
        for nodewalk={%
          Nodewalk={%
            on invalid=fake,
          }{%
            parent,
          }{%
            for children={anchor=north},
          }
        }{},
      }{},
    },
  },
}

\begin{document}
\begin{forest}
  nice empty nodes
  [
    [b]
    [
      [c]
      [
        [b]
        [a]
      ]
    ]
  ]
\end{forest}
\end{document}

更好的空節點?

相關內容