4

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?

  • You can use forest's linguistics library with nice empty nodes and sn edges in most cases. – cfr Mar 18 '17 at 19:49
  • Why do you need tikz-qtree rather than qtree exactly? – cfr Mar 18 '17 at 23:17
  • I need it to draw arrows between nodes... – RobertP. Mar 19 '17 at 14:17
  • You could use tikzmark with qtree. I've added a solution based on this to my answer below. I would probably use this if I didn't want to change to forest and think about using forest for future projects, if applicable. That is, unless somebody like Alan Munn comes along with a tikz-qtree solution. – cfr Mar 19 '17 at 14:40
2

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.

6

Not qtree nor tikz-qtree but forest :):

\documentclass[11pt]{article}
\usepackage{forest}

\begin{document}
\begin{forest}
for tree={% style of tree
  font=\scshape,
  anchor=base,
  calign=fixed edge angles,
  delay={where content={}{shape=coordinate}{}},
  inner sep=1pt,
}
[
  [
    [
     [$\sqrt{\textsc{Root}}$] [Voice]
    ]
    [Asp]
  ]
  [Tns]
]
\end{forest}
\end{document}

enter image description here

  • I can't learn another package right now, so I was wondering if there is a way to do it with tikz-qtree – RobertP. Mar 18 '17 at 20:09
  • For example, to me learning forest make me less troubles than learning tikz-qtree. Let me emphasize that it was developed for use in linguistic. And here on site are many active many excellent gurues, who will be glad to help you. Don't hesitate to start use it,First example you already have, and on the site are plenty more complicated examples. – Zarko Mar 18 '17 at 21:51
  • 1
    Yes. But the syntax is different and it has a rather steeper learning curve than tikz-qtree. If @RobertP. has a project with trees in tikz-qtree/qtree syntax it is non-trivial to convert them all and attempting to learn Forest should not be attempted with a clock ticking against an imminent deadline, for example. At least, I surely wouldn't like to do it and would not recommend it. – cfr Mar 18 '17 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.