Format particular terminal nodes and remove lines between them and their parents using forest

forestlinguisticstikz-pgftrees

When using the forest package to draw linguistic syntax trees, how can one prevent lines being drawn between particular terminal nodes and their parents, while still maintaining them as separate "nodes" as viewed by forest/TikZ in order to facilitate programmatic formatting?

Here is an example of the desired output (produced using my current workaround as given in the MWE below):

example-desired-output-tree

My current workaround involves the following which requires too much manual intervention:

  • I remove lines between a "terminal node" and its "parent" by creating a single node and then forcing a line break between the syntactic category (if present) and its lexical realisation (if present), e.g. [DP\\the apple].
  • Terminal nodes that have lexical items have these items manually decorated by colouring them with the xcolor package (e.g. [DP\\\textcolor{blue}{the apple}].

Ideally, I'd like to be able to programmatically apply something like the following code inside the forest environment:

for tree={
    if n children=0{
        text=blue
    }{},
}

However, adding the above snippet produces the following undesired output:

example-undesired-output-tree

I figure the solution might have something to do with setting up a type of "lexical terminal node" (i.e. terminal nodes that are of a lexical type instead of empty or a syntactic category), and then only applying the text decoration to nodes of that type. However, I'm not sure how to do this within forest, or if it is good/optimal solution.

Minimal Working Example (current workaround)

\documentclass[a4paper]{article}

% ----- Package Imports -----
\usepackage{amsmath, amssymb, amsthm, mathtools} % Math enhancements
\usepackage{newpxtext, newpxmath} % Palatino fonts (load after amssymb)
\usepackage[svgnames]{xcolor} % Custom colours
%\usepackage[style=ieee]{biblatex} % Bibliography
\usepackage[linguistics]{forest} % Linguistic syntax trees

\begin{document}
\begin{forest}
    [CP
        [\phantom{X}]
        [C'
            [C]
            [TP 
                [\phantom{X},name=TP-spec]
                [T'
                    [T\\\textcolor{blue}{$\varnothing_{\text{past}}$},name=TP-head]
                    [VoiceP 
                        [DP\\\textcolor{blue}{Bill}]
                        {\draw[->] () to[out=south west,in=west,distance=2cm] (TP-spec);}
                        [Voice' 
                            [Voice\\\textcolor{blue}{$\varnothing_{\text{active}}$}]
                            [VP 
                                [DP]
                                [V'
                                    [V\\{[}FORM preterite{]}\\\textcolor{blue}{ate}]
                                    [DP\\\textcolor{blue}{the apple}]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]
\end{forest}
\end{document}

Best Answer

Applying no edge to a node prevents the edge to its parent being drawn.

The combination of l sep=0 on the parent node and l=0 on the child node gets them vertically close to each other.

I find the result most pleasing if I additionally set inner ysep=0 on the child (this gets the category and lexical content even a bit closer), and override Forest's align (which puts the node content in a tabular environment, and thereby creates some extra vertical space) by TikZ's align: \forestset{align/.style={/tikz/align={#1}}}.

\documentclass[a4paper]{article}

% ----- Package Imports -----
\usepackage[svgnames]{xcolor} % Custom colours
\usepackage{amsmath, amssymb, amsthm, mathtools} % Math enhancements
\usepackage{newpxtext, newpxmath} % Palatino fonts (load after amssymb)
%\usepackage[style=ieee]{biblatex} % Bibliography
\usepackage[linguistics]{forest} % Linguistic syntax trees

\forestset{align/.style={/tikz/align={#1}}}

\begin{document}
\begin{forest}
  for tree={
    if n children=1{
      l sep=0,
      for 1={no edge, l=0, inner ysep=0, blue}
    }{},
  }
    [CP
        [\phantom{X}]
        [C'
            [C]
            [TP 
                [\phantom{X},name=TP-spec]
                [T'
                    [T[$\varnothing_{\text{past}}$,name=TP-head]]
                    [VoiceP 
                        [DP[Bill]
                          {\draw[->] () to[out=south west,in=west,distance=2cm] (TP-spec);}
                        ]
                        [Voice' 
                            [Voice[$\varnothing_{\text{active}}$]]
                            [VP 
                                [DP]
                                [V'
                                    [V\\{[}FORM preterite{]}[ate]]
                                    [DP[the apple]]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]
\end{forest}
\end{document}

effect of modifications on typeset tree

Related Question