4

Is it possible to use a symbol in a node as an anchor? I want to draw lines from the \circ symbol in a parent to the childs. I want to do something like for tree={parent anchor=\circ, child anchor=north} (this does of course not work).

MWE:

\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}
2
  • 1
    You cannot do this. You could fake it. But it would be easier to fake it by splitting nodes than by adjusting alignments, I think. There are some similar examples on the site already: probably you could use one of the strategies from there.
    – cfr
    Nov 21, 2017 at 5:14
  • @cfr Thank you for your comment. I'm just starting to use tikz and forest, can you provide a link to "splitting nodes" that is easy to follow?
    – J. Kamans
    Nov 21, 2017 at 14:11

1 Answer 1

4

Here's the general idea. No doubt requires some tweaking.

The node content is entered as <left part> : <right part>. The colon will be replaced by \circ during processing. The left and right parts will be split out to create new nodes to the left and right of the \circ. Nodes containing * are not touched. A phantom root is added as the root cannot have siblings.

\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}

tree with split nodes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .