[Tex/LaTex] qtree and tikz-qtree

linguisticsqtreetikz-qtree

I need to use tikz-qtree instead of qtree, but I noticed that trees are annoyingly uneven. Compare the following tree created with tikz-qtree:

% !TEX TS-program = latex
\documentclass[11pt]{article}
\usepackage{tikz, tikz-qtree, pst-node, pst-asr, graphicx}
\tikzset{every tree node/.style={align=center, anchor=north}}
%\usepackage{qtree}

\begin{document}

\Tree [  [  [ $\sqrt{\textsc{Root}}$ {\scshape Voice} ] [.{\scshape Asp} ] ] [.{\scshape Tns} ] ]

\end{document}

enter image description here

with the following created with qtree:

% !TEX TS-program = latex
\documentclass[11pt]{article}
%\usepackage{tikz, tikz-qtree, pst-node, pst-asr, graphicx}
%\tikzset{every tree node/.style={align=center, anchor=north}}
\usepackage{qtree}

\begin{document}

\Tree [.  [.  [.  $\sqrt{\textsc{Root}}$ {\scshape Voice} ] [.{\scshape Asp} ] ] [.{\scshape Tns} ] ]

\end{document}

enter image description here

Is it possible to compiles trees with tikz-qtree as nice as those with qtree somehow?

Best Answer

EDIT (Now with 3 solutions)

qtree + tikzmark

If you just need to draw arrows later, you can use tikzmark with qtree. At least, the following seems to work:

\documentclass{article}
\usepackage{qtree,tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}
  \Tree [  [  [ {\tikzmark{a}$\sqrt{\textsc{Root}}$\tikzmark{b}} {\scshape Voice} ] [.{\scshape Asp} ] ] [.{\scshape {\tikzmark{c}Tns\tikzmark{d}}} ] ]
\begin{tikzpicture}[overlay, remember picture]
  \draw [->, shorten >=5pt, shorten <=5pt] ($(pic cs:a)!1/2!(pic cs:b)$) .. controls +(1,-2) and +(-1,-2) .. ($(pic cs:c)!1/2!(pic cs:d)$);
\end{tikzpicture}
\end{document}

<code>qtree</code> + <code>tikzmark</code>

forest

I would also use Forest, but would definitely recommend the linguistics library which provides nice empty nodes and suitable edges out-of-the-box. To align the terminal nodes, you can add a phantom with zero width but appropriate height.

For example,

\documentclass{standalone}
\usepackage[linguistics]{forest}
\begin{document}
\begin{forest}
  nice empty nodes,
  for tree={
    font=\scshape,
  },
  before typesetting nodes={
    where n children=0{
      +content=\makebox[0pt]{\phantom{$\sqrt{X}$}},
    }{}
  }
  [
    [
      [
        [$\sqrt{\textsc{Root}}$]
        [Voice]
      ]
      [Asp]
    ]
    [Tns]
  ]
\end{forest}
\end{document}

Forest with <code>linguistics</code> library

tikz-qtree

If you prefer to stick with tikz-qtree, you should wait to see what Alan Munn can come up with. I've only ever used qtree and forest, so the best I can do with tikz-qtree is

<code>tikz-qtree</code> effort

\documentclass[border=10pt]{standalone}
\usepackage{tikz-qtree}
\begin{document}
\newlength\widesttreenodewidth
\settowidth{\widesttreenodewidth}{$\sqrt{\textsc{Root}}$}
\newlength\highesttreenodeht
\settoheight{\highesttreenodeht}{$\sqrt{\textsc{Root}}$}
\newlength\deepesttreenodedpth
\settodepth{\deepesttreenodedpth}{$\sqrt{\textsc{Root}}$}
\tikzset{
  every tree node/.append style={text width=\widesttreenodewidth, text depth=\deepesttreenodedpth, text height=\highesttreenodeht, text centered},
  execute at begin node=\makebox[0pt]{\phantom{$\sqrt{X}$}},
}
\Tree [  [  [ $\sqrt{\textsc{Root}}$ {\scshape Voice} ] [.{\scshape Asp} ] ] [.{\scshape Tns} ] ]
\end{document}

Note

Forest does take some time to learn and the syntax is a bit different, so it is not something to attempt at the end of a large project, deadline looming, for sure.

Related Question