4

I am trying to make basic linguistic trees in Forest that do two things: 1) have the bottom leaves aligned on a single tier, and 2) have parent anchor=south. (Actually I have a third requirement as well: to be able to use line-breaks in leaves, but that's another issue.) Currently I can brute force these together by specifying the tier for each leaf as needed (fine for the occasional small tree, irritating for many or larger trees).

The Forest documentation ( http://mirrors.ibiblio.org/CTAN/graphics/pgf/contrib/forest/forest-doc.pdf ) does provide a technique for doing this alignment automatically (p. 7, ex. 12), but if I try this while also specifying parent anchor I get this error:

! Package pgfkeys Error: I do not know the key '/tikz/{parent anchor=south} whe re n children', to which you passed '0{tier=word}{}', and I am going to ignore it. Perhaps you misspelled it.

I am very new to Forest, so maybe I'm missing something obvious. Below is my MWE, first with the brute-forced version A that gives the correct output:

enter image description here

And this is followed by the automated version that produces the correct alignment, but without any parent anchoring specified (I've included the line the breaks it, but commented out):

![enter image description here

I would like to be able to use an automated alignment, as in B, but with the anchoring of A. Thank you.

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage{forest}

\begin{document}

A) Correct tree, but brute-forced:

\begin{forest}{parent anchor=south}
[
[strong
    [strong[Cant,tier=word]]
    [weak[wara,tier=word]]
]
[weak
    [byrig,tier=word]
]
]   
    \end{forest}

B) Automated tree, but with wrong parent anchor:

\begin{forest}%{parent anchor=south}
where n children=0{tier=word}{}
[
[strong
    [strong[Cant]]
    [weak[wara]]
]
[weak
    [byrig]
]
]   
\end{forest}

\end{document}
  • What language is this? – cfr Sep 5 '18 at 4:12
3

You are simply using a not completely correct syntax. The options/instructions need to be separated by commas (and there is no need for braces). EDIT: Added for tree. Big thanks to @cfr, who has the only real answer to this question. My post was merely to keep this question active. (A little bit like the unknown band that plays before the real stars start. ;-)

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage{forest}

\begin{document}

A) Correct tree, but brute-forced:

\begin{forest}
parent anchor=south
[
[strong
    [strong[Cant,tier=word]]
    [weak[wara,tier=word]]
]
[weak
    [byrig,tier=word]
]
]   
    \end{forest}

B) Automated tree and correct parent anchor:

\begin{forest}
for tree={parent anchor=south},
where n children=0{tier=murmel}{}
[
[strong
    [strong[Cant]]
    [weak[wara]]
]
[weak
    [byrig]
]
]   
\end{forest}

\end{document}

enter image description here

I will be happy to remove this when @cfr comes online. ;-)

  • 1
    :-) Indeed. We should clean up, though. – cfr Sep 6 '18 at 2:20
2

The easy way to do this, with current Forest, is to use the linguistics library:

\usepackage[linguistics]{forest}

for multi-line, centred nodes with parent anchor=children throughout, and other goodies.

If you don't have current Forest and cannot update, you can do it manually. As marmot says, you need commas to separate TikZ options, but you are also only setting the parent anchor for the root. Instead, use something like this

  for tree={% sets things for the whole tree
    parent anchor=children,%  children is better than south unless you really mean south or can't use current forest
%     align=center,% if you want multi-line nodes for the whole tree 
  },
  where n children=0{tier=twrllaod, align=center,% mulit-line nodes
  }{}

manual result

With current Forest, you can load the library and then just say

  where n children=0{tier=twrllaod}{}

auto result

You may also find nice empty nodes and/or roof of some use to you.

\documentclass[border=5pt]{standalone}
% \usepackage[linguistics]{forest}% use this to apply the library settings globally
\usepackage{forest}
\useforestlibrary{linguistics}
\begin{document}

\begin{forest}%{parent anchor=south}% this only sets the parent anchor for the root node - not the whole tree
  for tree={% sets things for the whole tree
    parent anchor=children,%  children is better than south unless you really mean south or can't use current forest
%     align=center,% if you want multi-line nodes for the whole tree 
  },
  where n children=0{tier=twrllaod, align=center,% mulit-line nodes
  }{}
  [
  [strong
      [strong[Cant]]
      [weak[wara]]
  ]
  [weak
      [byrig]
  ]
  ]   
\end{forest}

\forestapplylibrarydefaults{linguistics}

\begin{forest}% multi-line nodes, parent anchor=children etc.
  where n children=0{tier=twrllaod}{}
  [
  [strong
      [strong[Cant]]
      [weak[wara]]
  ]
  [weak
      [byrig]
  ]
  ]   
\end{forest}


\end{document}

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.