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 tree
statement 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.
\mathnormal{\mathit{#1}}
is the same as\mathit{#1}
as math font commands don't combine.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.\forestset{auto name/.style={delay={name=\forestoption{content}}}}
?name
? Why not justdelay={for tree={alias/.option=content}}
?