3

I draw a lot of connections between nodes by hand. For this the easiest way is to give the nodes the names that correspond to their node labels. The node that is displayed as clause should also have the name clause. Is there a clever for treestatement that does this?

\documentclass{article}

\usepackage{forest}
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}

\newcommand{\type}[1]{\ifmmode\mathnormal{\mathit{#1}}\else\textnormal{\textit{#1}}\fi}


\forestset{
  % Easy extra edges
  edge to'/.style 2 args={
    tikz+={\path[#2](#1.parent anchor)--(.child anchor);}
  },
  edge to/.style={
    edge to'/.expanded={\unexpanded{#1}}{\forestoption{edge}},
  },
  edge from'/.style 2 args={
    tikz+={\path[#2](.parent anchor)--(#1.child anchor);}
  },
  edge from/.style={
    edge from'/.process=_O{#1}{#1.edge},
  },
  % Identify two (adjacent, vertically aligned) nodes.  See the explanation of
  % how this works in "type-hierarchies.tex"
  identify/.style={
    phantom,
    temptoksa/.option=#1.name,
    before typesetting nodes/.process=Rw1{temptoksa}{
      content/.option=##1.content,
      content format/.option=##1.content format,
      node format/.option=##1.node format,
    },
    for parent/.process=Ow1{n}{
      after packing node={
        for ##1={
          ignore,ignore edge,forget@node@boundary/.option=grow,
        },
      },
    },
    for nodewalk/.process=Rw1Ow1{temptoksa}{name=##1}{!u.name}{edge to={##1}},
  },
  forget@node@boundary/.code={%
    \forestolet{positive@edge@#1}\relax
    \forestolet{negative@edge@#1}\relax
  },
  % Uniformly spread any sequence of nodes
  spread/.style n args=4{
    % #1 = coordinate (x,y,s,l)
    % #2 = nodewalk to spread
    % #3 = relative node name of the node with the final coordinate
    % #4 = final coordinate shift
    for nodewalk={
      tempcounta'=-1,
      #2,
      tempdima/.pgfmath={(#1("#3")+#4-#1(""))/tempcounta()}
    }{tempcounta'+=1},
    tempdimb'=0pt,
    for nodewalk={#2}{
      #1'+/.register=tempdimb,
      tempdimb'+/.register=tempdima,
    },
  },
}

% The old type hierarchy style
\forestset{
typehierarchy/.style={for tree={parent anchor=south, child
% old version:
%    anchor=north,align=center,base=top,font=\itshape,fit=rectangle}},
% to get parallel lines:
    anchor=north,align=center,base=top,font=\itshape,calign=fixed angles}},
% if there are instances as leaves in the hiarchy
instance/.style={edge=dotted}
}

% Type hierarchy (Saso 2020)
\forestset{
  type hierarchy/.style={
    for tree={
      anchor=base,
      content format={\noexpand\type{\unexpanded{#1}\forestoption{content}}},
    },
  },
  attrib/.style={
    content format={\noexpand\attrib{\forestoption{content}}},
    draw,
  },
}

% Type hierarchy (Saso 2020)
\forestset{
  type hierarchy/.style={
    for tree={
      anchor=base,
      content format={\noexpand\type{\unexpanded{#1}\forestoption{content}}},
    },
    % The \ldots should not be in italics, so we add \normalfont to the original definition. Saso 27.05.2020
    TeX={
      \let\origldots\ldots
      \def\ldots{\normalfont\origldots}%
    },
    % Saso suggested the above rather than looking at the content, but we may use looking at the
    % content for replacing "...":
    delay={where content={...}{content=\normalfont\ldots}{}},
  },
  % Partitions are typeset in small caps (\textsc) and put in boxes (draw).
  partition/.style={
    content format={\noexpand\textsc{\forestoption{content}}},
    draw,
  },
  instance/.style={
    gray,edge={gray,dashed},align=center
  },
  % if all leaves in the hierarchy are instances, we can declare this as follows:
  % nodes which do not have children (n children=0) are drawn in gray and edges leading to them are dashed 
  instances/.style={
      for tree={
      s sep=0,
      if n children=0{
        instance   % easier to maintain if we use the style than repeat the definition of the style
      }{},
  }},
}



\begin{document}


\begin{forest}
type hierarchy, 
[finite-clause
  [internal-syntax, partition
    [root
      [v2 
        [r-wh-int, name=r-wh-int, tier=max]
        [r-decl, name=r-decl, tier=max]]
      [v1 [r-pol-int, name=r-pol-int]]]
    [subord, name=subord]]
  [clausality, partition
    [inter
      [wh, name=wh, tier=wh-polar-decl
        [s-wh-int, name=s-wh-int, tier=max]]
      [polar, name=polar, tier=wh-polar-decl
        [s-pol-int, name=s-pol-int, tier=max]]]
    [decl, name=decl, tier=wh-polar-decl
        [s-decl, name=s-decl, tier=max]]]]
\draw (wh.south) -- (r-wh-int.north);
\draw (subord.south) -- (s-wh-int.north);
\draw (subord.south) -- (s-pol-int.north);
\draw (subord.south) -- (s-decl.north);
\draw (polar.south) -- (r-pol-int.north);
\draw (decl.south) -- (r-decl.north);
\end{forest}

\end{document}

An additional question would be whether there is a way of getting rid of the .south and .north statements for the \draw statements. Maybe by defining a new command that always draws from south to north.

10
  • 1
    not related to the question but \mathnormal{\mathit{#1}} is the same as \mathit{#1} as math font commands don't combine. Commented Jul 13 at 10:52
  • Can you imagine a node named "A very\\long name\\over three lines"? Now a TikZ matrix will create node names consisting of a base name-row-column. Commented Jul 13 at 12:19
  • @john-kormylo I do not understand the question. I just asked for the simple case. I am looking for something like for tree={name=label}, but do not know how to do this. For my application case the node labels correspond to types. No newlines involved. Commented Jul 13 at 12:28
  • 1
    Isn't it sufficient to do something like \forestset{auto name/.style={delay={name=\forestoption{content}}}}?
    – Alan Munn
    Commented Jul 13 at 12:54
  • 1
    Why do you need name? Why not just delay={for tree={alias/.option=content}}?
    – cfr
    Commented Jul 13 at 16:26

1 Answer 1

7

I find that alias typically works well in this kind of case. I've also partially minimised your preamble as most of your configuration isn't needed for the example and some of it either duplicates or overwrites earlier parts.

\documentclass{standalone}
\usepackage[linguistics]{forest}
\newcommand{\type}[1]{\ifmmode\mathnormal{\mathit{#1}}\else\textnormal{\textit{#1}}\fi}

% Type hierarchy (Saso 2020)
\forestset{
% Type hierarchy (Saso 2020)
  type hierarchy/.style={
    for tree={
      anchor=base,
      content format={\noexpand\type{\unexpanded{#1}\forestoption{content}}},
    },
    % The \ldots should not be in italics, so we add \normalfont to the original definition. Saso 27.05.2020
    TeX={
      \let\origldots\ldots
      \def\ldots{\normalfont\origldots}%
    },
    % Saso suggested the above rather than looking at the content, but we may use looking at the
    % content for replacing "...":
    delay={where content={...}{content=\normalfont\ldots}{}},
  },
  % Partitions are typeset in small caps (\textsc) and put in boxes (draw).
  partition/.style={
    content format={\noexpand\textsc{\forestoption{content}}},
    draw,
  },
}
\begin{document}
\begin{forest}
  type hierarchy, 
  before typesetting nodes={
    where={> O_={tier}{max}}{l*=1.5}{},
    for tree={alias/.option=content},
  },
  [finite-clause
    [internal-syntax, partition
      [root
        [v2 
          [r-wh-int, , tier=max]
          [r-decl, , tier=max]]
        [v1 [r-pol-int, tier=max, ]]]
      [subord, ]]
    [clausality, partition
      [inter
        [wh,  tier=wh-polar-decl
          [s-wh-int, , tier=max]]
        [polar, , tier=wh-polar-decl
          [s-pol-int, , tier=max]]]
      [decl, , tier=wh-polar-decl
          [s-decl, , tier=max]]]]
  \draw (wh.south) -- (r-wh-int.north);
  \draw (subord.south) -- (s-wh-int.north);
  \draw (subord.south) -- (s-pol-int.north);
  \draw (subord.south) -- (s-decl.north);
  \draw (polar.south) -- (r-pol-int.north);
  \draw (decl.south) -- (r-decl.north);
\end{forest}

\end{document}

tree with alias for connections

3
  • 1
    Note that I don't really see the need for content format here. Why not just font=\scshape in the definition of partition, for example?
    – cfr
    Commented Jul 13 at 17:44
  • 1
    I think this does not work since the other nodes call \typewhich sets the nodes in italics. Maybe one could call font for the other nodes and then this would be overwritten. Commented Jul 14 at 7:22
  • 1
    @StefanMüller Oh, possibly. You might end up with italic small-caps. Or just italic. I guess it is the math-or-text issue, maybe, to do it this way.
    – cfr
    Commented Jul 14 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .