4

I'm having a problem with creating some abstract syntax trees with the Forest package. As is clear below, there is a large gap between the siblings even though there is no need for such a gap, but I can't find anything in the documentation about this issue.

This is what I'm able to create in TeX

Below you can see how I've created the current tree. I'm thinking I need to align the nodes to the left somehow, if I want to get a tree looking like my drawing in the bottom of this post.

\begin{forest}
for tree={
    before typesetting nodes={content=\texttt{#1}}
}
[<regexp>, s sep=0pt
    [(seq]
    [<regexp>, edge={draw=none}
        [(atom 1)]
    ]
    [<regexp>), edge={draw=none}
        [(seq]
        [<regexp>, edge={draw=none}
            [(atom 2)]
        ]
        [<regexp>), edge={draw=none}
            [(seq]
            [<regexp>, edge={draw=none}
                [(atom 3)]
            ]
            [<regexp>), edge={draw=none}]
        ]
    ]
]
\end{forest}

This is what I'm looking for, but not able to create:

Drawing

  • I think what you need is calign=first – Salim Bou Apr 27 '17 at 17:54
4

I think you need the for tree option calign=first. I.e.

\documentclass{book}
\usepackage[linguistics]{forest}
\begin{document}
\begin{forest}
for tree={
    before typesetting nodes={content=\texttt{#1},
    calign=first}
}
[<regexp>, s sep=0pt
    [(seq]
    [<regexp>, edge={draw=none}
        [(atom 1)]
    ]
    [<regexp>), edge={draw=none}
        [(seq]
        [<regexp>, edge={draw=none}
            [(atom 2)]
        ]
        [<regexp>), edge={draw=none}
            [(seq]
            [<regexp>, edge={draw=none}
                [(atom 3)]
            ]
            [<regexp>), edge={draw=none}]
        ]
    ]
]
\end{forest}
\end{document}

Outputs:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy