Here you have a starting point:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\begin{tikzpicture}[
tlabel/.style={pos=0.4,right=-1pt,font=\footnotesize\color{red!70!black}},
]
\node{S}
child {node {a}}
child {node {S}
child {node {a}}
child {node {S}
child {node {$\varepsilon$}
edge from parent node[tlabel,pos=0.2] {2}
}
edge from parent node[tlabel] {1}
}
child {node {B}
child {node {B}
child {node {b}
edge from parent node[tlabel,pos=0.2] {5}
}
edge from parent node[tlabel] {4}
}
child {node {b}}
}
edge from parent node[tlabel] {1}
}
child {node {B}
child[missing] {}
child[missing] {}
child {node {b}
edge from parent node[tlabel,pos=0.15,right=2pt] {5}
}
};
\end{tikzpicture}
\end{document}
There are various problems with your code. First, multirooted structures are not formally trees, so you can't expect tree drawing packages to handle them directly. See the following question for more discussion on techniques for this:
Furthermore, the syntax for a gb4e
example requires that the example be introduced by the \ex
macro (within the {exe}
environment.)
To handle the multidominance, I've used Ignasi's suggestion to create a node relative to the -|
path between node A and E. You could also use the TikZ positioning
library, to manually place the node. I've also removed the tikz-qtree
package, since it's not needed if you're using forest
. Since your 'tree' grows upwards, I've added baseline
to one of the terminal nodes so that it will align properly with the example number, and set the growth function globally for the tree. Also, you had a particular style for nodes in your example, but you never applied that style, and I've done that too.
You should also load gb4e
after most other packages, since it can cause problems otherwise.)
\documentclass{article}
\usepackage{forest}
\usepackage{gb4e}
\begin{document}
\begin{exe}
\ex
\begin{forest}
qtree edges/.style={for tree={parent anchor=north, child anchor=south}},
for tree={grow=north},qtree edges
[A, name=A,
[C, name=C
[E,baseline,name=E ]
[D, ]
]
[B ]
]
\node (F) at (A-|E) {F};
\draw (F.north) -- (C.south);
\end{forest}
\end{exe}
\end{document}
Best Answer
You can use two trees sitting on top of each other.
I'll leave the connection lines to you if you don't mind. You can access each node by first writing up the parent node name followed by a dash and the item number e.g.
(topnode-5)
.