# [Tex/LaTex] Decrease distance between nodes in tree using Forest

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:

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}