3

I'm using gb4e and forest to present (linguistic) trees in a nice format. It's been working well except that I some of the text underneath the nodes presented on multiple lines. In the forest package readme I've found the following code.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[extra]{tipa}
\usepackage[linguistics]{forest}
\usepackage{tikz}
\usepackage{tikz-qtree}
% For delinked segments
\usetikzlibrary{decorations,decorations.text}
\tikzset{delink/.style={
    decorate,
    postaction={decorate,
    decoration={text along path,
        text align=center,
        text={|\tiny|=},
        transform={rotate=90}}}}}
\usepackage{gb4e}

\begin{document}

\begin{exe}
\ex
\begin{xlist}
\ex
\begin{forest} GP1 [
 [parent
 [child]
 [child]
 [a very\\tall\\child, align=center, base=bottom]
 ]
 ]
\end{forest}
\end{xlist}
\end{exe}

\end{document}

Which yields what I want, namely that the text is displayed on multiple lines.

enter image description here

However when I apply this method to my own tree, I encounter the problem that it does not put the text on multiple lines. Here is the code.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[extra]{tipa}
\usepackage[linguistics]{forest}
\usepackage{tikz}
\usepackage{tikz-qtree}
% For delinked segments
\usetikzlibrary{decorations,decorations.text}
\tikzset{delink/.style={
    decorate,
    postaction={decorate,
    decoration={text along path,
        text align=center,
        text={|\tiny|=},
        transform={rotate=90}}}}}
\usepackage{gb4e}

\begin{document}

\begin{exe}
\ex
 \begin{xlist}
 \ex
 \begin{forest} GP1 [
 [x[k]]
 [x[\textipa{1}
 [a very\\tall\\child, align=center, base=bottom]
 ]]
 [x[z]]
 [x[\textipa{1}[| |]]]
 [x[n]]
 ]\end{forest}
 \end{xlist}
\end{exe}

\end{document}

Which yields the following output.

enter image description here

Is there any way to fix this is issue and make the text appear on multiple lines?

EDIT: edited to include MWE

  • Can you provide an MWE that compiles, and not just code fragments? Welcome to the site. – Steven B. Segletes May 8 '18 at 14:57
  • @StevenB.Segletes Edited to include MWE's – L. Suurmeijer May 8 '18 at 15:12
  • @StevenB.Segletes I've edited my answer in your honour. :) – Alan Munn May 8 '18 at 15:14
3

This has nothing to do with gb4e, but with the definition of the GP1 style in forest. There are at least three ways to fix this:

Use an explicit tabular

You can put the node inside an explicit tabular:

\documentclass{article}
\usepackage[extra]{tipa}
\usepackage[linguistics]{forest}
\usepackage{tikz}
\usepackage{gb4e}

% For delinked segments
\usetikzlibrary{decorations,decorations.text}
\tikzset{delink/.style={
decorate,
postaction={decorate,
decoration={text along path,
    text align=center,
    text={|\tiny|=},
    transform={rotate=90}}}}}
\begin{document}
\begin{exe}
\ex
 \begin{xlist}
 \ex
 \begin{forest} GP1 [
 [x[k]]
 [x[\textipa{1}
 [{\begin{tabular}{c}a very\\tall\\child\end{tabular}}]
 ]]
 [x[z]]
 [x[\textipa{1}[| |]]]
 [x[n]]
 ]\end{forest}
 \end{xlist}
\end{exe}
\end{document}

output of code

Use the stackengine package

Alternatively, you could use the stackengine package to do the same thing:

\usepackage{stackengine}
\begin{forest} GP1 [
  [x[k]]
  [x[\textipa{1}
  [{\Shortunderstack[c]{{a very} tall child}}]
  ]]
  [x[z]]
  [x[\textipa{1}[| |]]]
  [x[n]]
]\end{forest}

Redefine the forest GP1 style

If you're going to be doing this a lot, it might make more sense to redefine the GP1 style slightly, so that the nodes behave as you would expect:

\documentclass{article}
\usepackage[extra]{tipa}
\usepackage[linguistics]{forest}
\usepackage{tikz}
\usepackage{gb4e}
% For delinked segments
\usetikzlibrary{decorations,decorations.text}
\tikzset{delink/.style={
decorate,
postaction={decorate,
decoration={text along path,
    text align=center,
    text={|\tiny|=},
    transform={rotate=90}}}}}
\forestset{GP1/.style 2 args={
    for n={1}{baseline},
    s sep=0pt, l sep=0pt,
    for descendants={
      l sep=0pt, l={#1},
      anchor=base,calign=first,child anchor=north,
      inner xsep=1pt,inner ysep=2pt,outer sep=0pt,s sep=0pt
    },
    delay={
      if content={}{phantom}{for children={no edge}},
      for tree={
        if content={O}{tier=OR}{},
        if content={R}{tier=OR}{},
        if content={N}{tier=N}{},
        if content={x}{
          tier=x,content={$\times$},outer xsep={#2},
          for tree={calign=center},
          for descendants={content format={\noexpand\standardnodestrut\forestoption{content}}},
          before drawing tree={outer xsep=0pt,delay={typeset node}},
          s sep=4pt
        }{align=center}, % changed the style here
      },
    },
    before drawing tree={where content={}{parent anchor=center,child anchor=center}{}},
  }}
\begin{document}
\begin{exe}
\ex
 \begin{xlist}
 \ex
 \begin{forest} GP1 [
 [x[k]]
 [x[\textipa{1}
 [{a very\\ tall \\child}]
 ]]
 [x[z]]
 [x[\textipa{1}[| |]]]
 [x[n]]
 ]\end{forest}
 \end{xlist}
\end{exe}
\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.