0

I'm trying to create the following in the forest TikZ-based package:

example graph

The square nodes require two things I don't know how to do in forest:

  • Visually split node into 2 parts, a left and a right
  • Have the arrow coming out of the middle of one of the parts to a child (will always be just 1 child)

If there's a way to simply place a node adjacent to another, that would be a possible solution.

Here's what I have so far:

\begin{forest}
    [,draw,circle
        [$\lnot B \rvert .$,draw,edge=->
            [,draw,circle,edge=->]
        ]
        [$. \rvert C$,draw,edge=->
            [,draw,circle,edge=->]
        ]
        [$. \rvert \top$,draw,edge=->
            [,draw,circle,edge=->]
        ]
    ]
\end{forest}

Produces this:

graph so far

Clearly, the vertical bar splitting the rectangular nodes is not tall enough and, most importantly, the arrow coming out of the rectangular nodes are not from the bottom center as opposed to the left or right half of the node.

2
  • It is likely that it is possible to do this by setting the parent anchor appropriately, but it would help a lot if you posted a code that answers can be based on.
    – user228539
    Nov 19, 2020 at 3:52
  • Good point @abcdefg, editing my answer now
    – at.
    Nov 19, 2020 at 4:07

1 Answer 1

2

Here is a very basic version that accomplishes this. I kept it basic, but you can simplify things by playing with forest keys that inherit styles. The basic things are:

  • use multipart nodes for the split schemes;
  • use append after command in order to add the bullet;
  • add a special edge style that accesses these bullet.

In practice, you need to use s2l or s2r, depending on whether the text is in the left or right cell, respectively, and you need to add \nodepart{two} at the end or beginning of the contents. Then you need to specify the cell the edge is supposed to start with special edge=one or special edge=two.

\documentclass{article}
\usepackage{amsmath}
\usepackage[edges]{forest}
\usetikzlibrary{shapes.multipart}
\tikzset{s2/.style={rectangle split,rectangle split horizontal,
    rectangle split parts=2,draw},
    sd/.style={append after command={%
    (\tikzlastnode.#1 south|-\tikzlastnode.center)
    coordinate[circle,inner sep=1pt,fill,alias=\tikzlastnode-cheat]}},
    s2l/.style={s2,sd=two},
    s2r/.style={s2,sd=one},
    c/.style={circle,draw,fill=gray,minimum size=1em}}

\forestset{special edge/.style={edge path'/.expanded={
(!u.#1 south|-!u.center) -- (.child anchor)
},edge=-stealth}}

\begin{document}


\begin{forest}
    [,c
        [$\lnot B$\nodepart{two},s2l,
            [,c,special edge=two]
        ]
        [\nodepart{two}$C$,s2r
            [,c,special edge=one]
        ]
        [\nodepart{two}$\top$,s2r
            [,c,special edge=one]
        ]
    ]
\end{forest}
\end{document}

enter image description here

1
  • Beautiful! Thank you
    – at.
    Nov 19, 2020 at 8:12

You must log in to answer this question.

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