使用节点中的符号作为锚点

使用节点中的符号作为锚点

是否可以使用节点中的符号作为锚点?我想从\circ父节点中的符号到子节点画线。我想做类似的事情for tree={parent anchor=\circ, child anchor=north}(这当然行不通)。

梅威瑟:

\documentclass[11pt]{article}
\usepackage{forest}

\begin{document}

\section{Default}

\begin{forest}
[$\varphi \lor (\psi \land \chi) \circ (\varphi \lor \psi) \land (\varphi \lor \chi)$
  [$\varphi \circ (\varphi \lor \psi) \land (\varphi \lor \chi)$
    [$\varphi \circ \varphi \lor \psi$
    [$\varphi \circ \varphi {,} \psi$
    [*]           
    ]           
    ]
    [$\varphi \circ \varphi \lor \chi$
    [$\varphi \circ \varphi {,} \chi$
    [*]           
    ]               
    ]
  ]
  [$\psi \land \chi \circ (\varphi \lor \psi) \land (\varphi \lor \chi)$
  [$\psi {,} \chi \circ (\varphi \lor \psi) \land (\varphi \lor \chi)$
    [$\psi {,} \chi \circ \varphi \lor \psi$
    [$\psi {,} \chi \circ \varphi {,} \psi$
    [*]           
    ]             
    ]
    [$\psi {,} \chi \circ \varphi \lor \chi$
    [$\psi {,} \chi \circ \varphi {,} \chi$
    [*]           
    ]                 
    ]           
  ]
  ]     
]
\end{forest}

\section{Now with anchors}

\begin{forest}
for tree={parent anchor=south, child anchor=north}
[$\varphi \lor (\psi \land \chi) \circ (\varphi \lor \psi) \land (\varphi \lor \chi)$
  [$\varphi \circ (\varphi \lor \psi) \land (\varphi \lor \chi)$
    [$\varphi \circ \varphi \lor \psi$
    [$\varphi \circ \varphi {,} \psi$
    [*]           
    ]           
    ]
    [$\varphi \circ \varphi \lor \chi$
    [$\varphi \circ \varphi {,} \chi$
    [*]           
    ]               
    ]
  ]
  [$\psi \land \chi \circ (\varphi \lor \psi) \land (\varphi \lor \chi)$
  [$\psi {,} \chi \circ (\varphi \lor \psi) \land (\varphi \lor \chi)$
    [$\psi {,} \chi \circ \varphi \lor \psi$
    [$\psi {,} \chi \circ \varphi {,} \psi$
    [*]           
    ]             
    ]
    [$\psi {,} \chi \circ \varphi \lor \chi$
    [$\psi {,} \chi \circ \varphi {,} \chi$
    [*]           
    ]                 
    ]           
  ]
  ]     
]
\end{forest}

\end{document}

答案1

这是总体思路。毫无疑问需要进行一些调整。

节点内容输入为<left part> : <right part>。处理过程中,冒号将被替换为\circ。左右部分将被拆分,以在 的左侧和右侧创建新节点\circ。包含 的节点*不受影响。phantom添加根,因为根不能有兄弟节点。

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\forestset{
  declare toks={left bit}{},
  declare toks={right bit}{},
  my anchors/.style={
    delay={
      for root={
        replace by={[, phantom, append]}
      },
    },
    before typesetting nodes={
      where={
        > O+tt= On=! & {content}{*} {level}{0}
      }{}{
        split option={content}{:}{left bit, right bit},
        delay={
          insert before/.process={
            Ow {left bit}{{[##1, math content, no edge]} }
          },
          insert after/.process={
            Ow {right bit}{{[##1, math content, no edge]}}
          },
          content=\circ,
          text height=\circht,
          text depth=\circdp,
          child anchor=parent,
          parent anchor=children,
          inner xsep=-100pt,
          math content,
        }
      }
    },
    before packing={
      where={
        > Ow+P {n children}{isodd(##1)}
      }{
        calign child/.process={Ow+n{n children}{(##1+1)/2}},
        calign=child edge,
      }{}
    }
  }
}
\newlength\circht
\settoheight{\circht}{$()\varphi$}
\newlength\circdp
\settodepth{\circdp}{$()\varphi$}
\begin{document}


\begin{forest}
  my anchors
  [\varphi \lor (\psi \land \chi) : (\varphi \lor \psi) \land (\varphi \lor \chi)
    [\varphi : (\varphi \lor \psi) \land (\varphi \lor \chi)
      [\varphi : \varphi \lor \psi
      [\varphi : \varphi {,} \psi
      [*]           
      ]           
      ]
      [\varphi : \varphi \lor \chi
      [\varphi : \varphi {,} \chi
      [*]           
      ]               
      ]
    ]
    [\psi \land \chi : (\varphi \lor \psi) \land (\varphi \lor \chi)
    [\psi {,} \chi : (\varphi \lor \psi) \land (\varphi \lor \chi)
      [\psi {,} \chi : \varphi \lor \psi
      [\psi {,} \chi : \varphi {,} \psi
      [*]           
      ]             
      ]
      [\psi {,} \chi : \varphi \lor \chi
      [\psi {,} \chi : \varphi {,} \chi
      [*]           
      ]                 
      ]           
    ]
    ]     
  ]
\end{forest}

\end{document}

具有分裂节点的树

相关内容