4

This should be a cakewalk but for some reason I can't find the key to it.

Following Alan Munn's suggestion, I have recently switched from qtree to forest for tree diagrams. Using the code:

\documentclass[11pt,a4paper,oneside,notitlepage]{book}
%...
\usepackage[linguistics]{forest}
%...
\begin{document}
%...
\begin{forest}
[A [B [C ] [D ] [E,edge=dotted ] ] [F [G ] ] ]
\end{forest}
%...
\end{document}

the following tree obtains:

enter image description here

How can I set a specific (shorter) length for the dotted line? I would like for node E to be positioned above the level of C, D, and G.

As the dotted line suggests, E is only remotely connected with what the tree represents, and I don't want it to be on the same level of the other bottom nodes.

poxx
  • 329

2 Answers2

4

You can specify the l parameter for a single node. It can lead to some funny results if you make the value too small, but for this purpose it seems to work.

\documentclass[11pt,a4paper,oneside,notitlepage]{book}
%...
\usepackage[linguistics]{forest}
%...
\begin{document}
%...
\begin{forest}
[A [B [C ] [D ] [E,edge=dotted,l=.75cm ] ] [F [G ] ] ]
\end{forest}
%...
\end{document}

output of code

Alan Munn
  • 218,180
  • This works, thanks. I also applied the same tier to C, D, and G to make E the only unaligned node. – poxx Jul 25 '17 at 09:42
  • (+1) l'=.75cm would be faster. – cfr Jul 26 '17 at 09:14
  • @cfr l' is an undocumented feature... (appears nowhere in the docs that I can see.) – Alan Munn Jul 26 '17 at 16:40
  • Page 36. It is a standard feature for all dimension options/registers. (Also integers etc.) – cfr Jul 26 '17 at 22:02
  • The evaluation of pgfmath can be quite slow. There are two tricks to speed things up if the pgfmath expression is simple, i.e. just a TEX dimen:

    1. pgfmath evaluation of simple values can be sped up by prepending + to the value [2, §62.1];
    2. use the key option’=value to invoke a normal TEX assignment.

    The two above-mentioned speed-up tricks work for the augmented assignments as well. The keys for the second, TEX-only trick are: ’+, ’-, ’*, ’: — note that for the latter two, the value should be an integer.

    – cfr Jul 26 '17 at 22:04
  • @cfr Thanks. I was looking specifically for l', since other similar keys show up in the index. – Alan Munn Jul 26 '17 at 22:20
  • 1
    Well, and you're right. l' is not specifically documented. It just isn't an undocumented feature, either. I have an advantage here: many of the avoid-pgfmath features were given a user interface when Sašo tried to figure out how prooftrees could be made faster and realised I was already using most of the (few) tricks available at the time, so provided some more. So we've been through prooftrees code trying to eliminate every use of pgfmath we could ... :-). Or, rather, I've followed Sašo through it .... – cfr Jul 26 '17 at 22:36
3

Forest also allows you to manually adjust the position of nodes before the tree is drawn (see chapter workflow, p.24 in forest manual). Note that x-=3 is augmented assignment.

\documentclass[11pt,a4paper,oneside,notitlepage]{book}
%...
\usepackage[linguistics]{forest}
%...
\begin{document}
%...
\begin{forest}
[A [B [C ] [D ] [E,edge=dotted, before drawing tree={x-=3mm, y+=3mm} ]
 ] [F [G ] ] ]
\end{forest}
%...
\end{document}

example

You can also change the inner ysep to adjust the distance between the dotted line and the node content.

\documentclass[11pt,a4paper,oneside,notitlepage]{book}
%...
\usepackage[linguistics]{forest}
%...
\begin{document}
%...
\begin{forest}
[A [B [C ] [D ] [E,edge=dotted, inner ysep=1pt, before drawing tree={x-=2mm, y+=2mm} ]
 ] [F [G ] ] ]
\end{forest}
%...
\end{document}

enter image description here

tebartsch
  • 335