0

In the following tree, the labels are concatenated to their parent node. For example in the first branch of the tree from left, I would like to have "the" as a leaf, but it sticks to D (its parent). This is the LaTeX code I use:

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[]{forest}
\forestset{.style={for tree={parent anchor=south, child anchor=north,align=center,inner sep=2pt}}}

\begin{forest}
[TP
    [DP [D\\the] [NP [N\\man ]]]
    [T'
        [T\\will ]
        [VP
            [V\\eat ]
                [DP [D\\a ] [NP [N\\burger ]]]
        ]
    ]
]
\end{forest}

Note: The code is taken from https://msu.edu/~amunn/latex/sharelatex-trees-forest-v1.pdf

This is the result of the code:

enter image description here

But I would like the results would be like this:

enter image description here

How can I fix this to have a tree like this:?

  • Please could you make your examples compilable? It makes it much easier and less pitfall-strewn to help. – cfr Dec 4 '18 at 0:17
3

Are you looking for something like this?

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[]{forest}
\begin{document}
\begin{forest}
[TP
    [DP [D,label=above left:the] [NP [N,label=above left:man
    ]]]
    [T'
        [T,label=above left:will ]
        [VP
            [V,label=above left:eat ]
                [DP [D,label=above left:a ] [NP [N,label=above left:burger ]]]
        ]
    ]
]
\end{forest}
\end{document}

enter image description here

Thanks for updating your question. You only need to make what you put in .style known to your tree.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[]{forest}
\begin{document}
\begin{forest}
for tree={parent anchor=south, child
anchor=north,align=center,inner sep=2pt}
[TP
    [DP [D\\the] [NP [N\\man ]]]
    [T'
        [T\\will ]
        [VP
            [V\\eat ]
                [DP [D\\a ] [NP [N\\burger ]]]
        ]
    ]
]
\end{forest}
\end{document}

enter image description here

I do not know where you got .style... from, I am not saying it is wrong but I have not seen it before. If you want every tree to have some universal for tree, consider using

\forestset{default preamble={
for tree={...}
}
}

as discussed on p. 7 of the manual.

  • Yeah, exactly, something like this but a bit cleaner and tidier (I updated my question with example) – woody Dec 3 '18 at 17:03
  • @woody I made an update. Is that closer to what you want? – marmot Dec 3 '18 at 18:46
  • 1
    It is wrong marmot and default preamble should be used. See page 99 of the Forest manual. @woody – cfr Dec 4 '18 at 0:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.