The Qtree package is "a LaTeX package for drawing tree diagrams." Is it possible to draw simple graph-like diagrams with it, similar to the one depicted below? If not, should I resort to TikZ-qtree?
[Tex/LaTex] Graph-like structures with Qtree
diagramsqtreetikz-qtree
Related Solutions
This isn't too hard to do with tikz-qtree
. In order to get the movement arrow from T to C to go under the VP, I made the object DP a node and used that as a reference point to create an intermediate node that the line passes through. Thanks very much to both Peter Grill and percusse for suggesting elegant ways to avoid the VP structure. The final solution is due to percusse, who also provided the nifty code to have the one arrow jump over the other.
\documentclass{article}
\usepackage{tikz-qtree, tikz-qtree-compat}
\tikzset{every tree node/.style={align=center, anchor=north}}
\usetikzlibrary{positioning}
\usepackage{fixltx2e}
\newcommand*\sub{\textsubscript}
\begin{document}
\begin{tikzpicture}
\Tree [.CP
[.\node (DP) {DP}; \edge[roof]; {Die Kinder} ]
[.C\1
[.\node (C) {C\\haben}; ]
[.TP [.\node (DPt1) {DP\\t\sub{i}}; ]
[.T\1
[.VP
[.VP [.\node (DPt2) {DP\\t\sub{i}}; ]
[.V\1
[.\node (Obj) {DP}; \edge[roof]; {diesen Film} ]
[.V\\gesehen ] ] ]
[.\node (Aux) {V\\t\sub{j}}; ] ]
[.\node (T) {T\\t\sub{j}}; ]]]]]
\node (DPn) [below=1cm of DP] {};
\draw [->] (DPt1) -| (DPn);
\draw [->] (DPt2) -| (DPt1);
\draw [->] (Aux.south) -| (T);
\draw [->] (T.east) |- ([yshift=-1.5cm] Obj.south)
-| ([yshift=-1.5mm]C |- DPt1) arc (-90:90:1.5mm) -- (C);
\end{tikzpicture}
\end{document}
It's hard to replicate qtree
spacing in tikz-qtree
since the latter package uses a completely different method for node spacing; most of the time this leads to much better looking trees, especially for linguistics, which was its intended use. You can balance out particular node manually by enclosing their contents in an explicit \node
command and specifiying a width. The imbalance comes from having very different widths dominated by by the nodes at the first level. See How do I center this qtree? for a similar problem. For the node size problem, I've used egreg's \phantom
solution.
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{tikz-qtree}
\tikzset{every tree node/.style={align=center,anchor=north}}
\newcommand{\bftt}[1]{\textbf{\texttt{#1}}}
\newcommand{\ts}[1]{\bftt{#1}\protect\vphantom{$A$}}
\begin{document}
\begin{tikzpicture}[]
\Tree [.$Z$ \node[minimum width=1cm]{\ts{(}}; [.$Z$ \ts{.} [.$Z$ \ts{(}
[.$Z$ $\epsilon$ ] \ts{)} [.$Z$ $\epsilon$ ] ] ] \node[minimum width=2cm]
{\ts{)}}; [.$Z$ $\epsilon$ ] ]
\end{tikzpicture}
\end{document}
A solution using the forest
package
The recent forest
package provides the tools to do this fairly easily. Although its main raison d'ĂȘtre is to make more compact trees, it provides hooks to make less compact trees too. The input syntax is a bit different: there are no .
to mark node labels, and terminal nodes must be enclosed in [ ... ]
.
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{forest}
\newcommand{\bftt}[1]{\textbf{\texttt{#1}}}
\newcommand{\ts}[1]{\bftt{#1}\protect\vphantom{$A$}}
\begin{document}
\forestset{qtree edges/.style={for tree={
parent anchor=south, child anchor=north}}}
\begin{forest}
[$Z$, qtree edges,s sep=1cm [\ts{(}] [$Z$ [\ts{.}] [$Z$ [\ts{(}] [$Z$ [$\epsilon$] ]
[\ts{)}] [$Z$ [$\epsilon$] ] ] ] [\ts{)}] [$Z$ [$\epsilon$] ] ]
\end{forest}
\end{document}
Best Answer
Here's one solution.
Update
I've changed the method of moving the P node so that it is centred correctly. (Output image has been put in an
\fbox
to show the image edges.)