# Decrease distance between nodes in tree using Forest

I have many trees in my latex document that are too big and make it hard to make the typesetting of the surrounding text look good. Therefore I want to decrease the vertical length of the tree by decreasing the distance between the nodes. I have tried the solution in this thread, by including this code:

  for tree={
l sep-=1em,
},


The only effect is that the distance between the node labeled DP and the node Manne, triangle, is decreased. The rest of them stay the same.

I have loaded the gb4e package in since I need it in the actual document and no reason related to the actual problem of this post.

\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage{forest, gb4e}

\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom{}}},
background tree/.style={for tree={text opacity=0.2,draw opacity=0.2,}},
qtree/.style={
baseline,
for tree={
parent anchor=south,
child anchor=north,
align=center,
inner sep=1pt,
}},
nice empty nodes/.style={for tree={calign=fixed edge angles},delay={where content={}{shape=coordinate,for parent={for children={anchor=north}}}{}}}
}
\tikzset{every tree node/.style={align=center,anchor=north}}
\begin{document}
\begin{exe}
\ex
\begin{forest}
for tree={
l sep-=1em,
},
qtree, nice empty nodes,
[TP
[T]
[\textit{v}P,
[sneehpeslaakan, triangle]]
[\textit{v}P
[DP
[Manne, triangle]]
[{}, s sep=15pt
[VP
[DP
[gærjah, triangle]]
[t{\scriptsize V}]]
[\textit{v} \\ lohk]]]]]
\end{forest}
%\end{xlist}
\end{exe}

\end{document}


I get the following output:

• Your 'triangle' style isn't defined. Can you add that. – Alan Munn Aug 5 '16 at 23:14
• The problem is caused by the nice empty nodes style. If you remove it, the tree gets nicer (except for the empty nodes...). – Alan Munn Aug 5 '16 at 23:19
• I think the 'triangle' is a default. I don not recall having defined it. – David Kroik Aug 5 '16 at 23:28
• Well as posted the example doesn't compile. – Alan Munn Aug 5 '16 at 23:33
• Is there a way to keep nice empty nodes and also alter the distance between the nodes? – David Kroik Aug 5 '16 at 23:34

The problem is due to the way the nice empty nodes style is defined. Here's a solution which gives a slightly different definition of nice empty nodes which I call fairly nice empty nodes. This definition will probably not be as successful with long strings of empty nodes, but for the occasional one as in your tree, it works quite well.

I've made some simplifications to your code, much of which has now been incorporated into the linguistics library of forest. I've also removed the utf8x input encoding, which generally shouldn't be used. The triangle style isn't defined by default, but there is a roof style which is, so I've used that instead. This is using forest v. 2.0.3 from TeXLive 2016v. 2.15 from TeXLive 2017. Code has been updated to reflect recent changes.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{forest, gb4e}

\forestset{
fairly nice empty nodes/.style={
delay={where content={}{shape=coordinate,
for siblings={anchor=north}}{}
}}}
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}
\begin{document}
\begin{exe}
\ex
\begin{forest}
fairly nice empty nodes,
[TP
[T]
[\textit{v}P,
[sneehpeslaakan, roof]]
[\textit{v}P
[DP
[Manne, roof]]
[{}, s sep=15pt
[VP
[DP
[gærjah, roof]]
[t{\scriptsize V}]]
[\textit{v} \\ lohk]]]]]
\end{forest}
\end{exe}

\end{document}


If you really want to squish the tree further, you can set l=0 and then change the value of l sep- to something a bit smaller. For example, setting

for tree={l sep-=.7em,l=0}


yields the following output:

## Forest v.1 version

It appears you are using forest v.1, which is why your code wouldn't compile for me. So here's a version using that version of forest. I've left the other code in the answer, since forest v.1 is now more than two years old, and hasn't been part of TeX Live since 2014, so other people who find this question (or you, if you update) may find the newer code useful.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{forest, gb4e}

\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom{}}},
background tree/.style={for tree={text opacity=0.2,draw opacity=0.2,}},
qtree/.style={
baseline,
for tree={
parent anchor=south,
child anchor=north,
align=center,
inner sep=1pt,
}},
nice empty nodes/.style={for tree={calign=fixed edge angles},delay={where content={}{shape=coordinate,for parent={for children={anchor=north}}}{}}},
fairly nice empty nodes/.style={
delay={where content={}{shape=coordinate,for parent={
for children={anchor=north}}}{}}
}}
\tikzset{every tree node/.style={align=center,anchor=north}}

\begin{document}
\begin{exe}
\ex
\begin{forest}
for tree={
l sep-=1em,
},
qtree, fairly nice empty nodes,
[TP
[T]
[\textit{v}P,
[sneehpeslaakan, triangle]]
[\textit{v}P
[DP
[Manne, triangle]]
[{}, s sep=15pt
[VP
[DP
[gærjah, triangle]]
[t{\scriptsize V}]]
[\textit{v} \\ lohk]]]]]
\end{forest}
\end{exe}

\end{document}

• triangle -> roof. Now we have nice empty nodes, pretty nice empty nodes, my pretty nice empty nodes and fairly nice empty nodes ... :-) – cfr Aug 6 '16 at 2:42
• @cfr Yes, you were my inspiration. But I didn't want to have a name conflict among * nice empty nodes :) – Alan Munn Aug 6 '16 at 2:49
• That is essentially why I used my pretty nice empty nodes at some point, I think, to avoid conflict with pretty nice empty nodes which was created to avoid conflict with nice empty nodes ;). – cfr Aug 6 '16 at 2:55
• I will update the Tex Live distribution to the newest version a shortly, but for present purposes I will stick to the current version. However, the new version of the example, using fairly nice empty nodes still gives rise to the same problem as my original example. Using a negativ value of the l sepstill only makes the DP Manne smaller, the other nodes have the same distance as when I exclude the command: for tree={ l sep-=1em, }, – David Kroik Aug 6 '16 at 8:33
• I updated the MacTex distribution to get the newest version of Forest, which now gives me full control over the distance of the nodes. – David Kroik Aug 9 '16 at 8:00