1

Based on the answer https://tex.stackexchange.com/a/270761/278762 from @GonzaloMedina. How can I control the vertical space y shown in the picture below

CODE:

\documentclass[border=5pt]{standalone}
\usepackage{forest}

\begin{document}

\begin{forest} for tree={ font=\ttfamily, grow'=0, child anchor=west, parent anchor=south, anchor=west, calign=first, edge path={ \noexpand\path [draw, \forestoption{edge}] (!u.south west) +(7.5pt,0) |- node[fill,inner sep=1.25pt] {} (.child anchor)\forestoption{edge label}; }, before typesetting nodes={ if n=1 {insert before={[,phantom]}} {} }, fit=band, before computing xy={l=15pt}, } [text1 [text1.1 [text1.1.1] [text1.1.2] [text1.1.3] ] [text1.2 [text1.2.1] [text1.2.2] ] ] \end{forest}

\end{document}

OUTPUT:

enter image description here

1 Answers1

1

If you want to change the spacing for all the children of text1.1, you can simply change s sep:

[text1
  [text1.1, s sep=1cm
    [text1.1.1]
    [text1.1.2]
    [text1.1.3]
  ]

enter image description here

On the other hand, if you only want to change the spacing above text 1.1.1, then you can add yshift= to the node:

enter image description here

[text1
  [text1.1
    [text1.1.1, yshift=-1.5cm]
    [text1.1.2]
    [text1.1.3]
  ]

If you want to do this for all the x.x.1 nodes, you can add it to the for tree:

if n children=0{if n=1{yshift=-1.5cm}{}}{}

enter image description here

Here is the complete code:

\documentclass{article}
\usepackage{forest}

\begin{document}

\begin{forest} for tree={ font=\ttfamily, grow'=0, child anchor=west, parent anchor=south, anchor=west, calign=first, edge path={ \noexpand\path [draw, \forestoption{edge}] (!u.south west) +(7.5pt,0) |- node[fill,inner sep=1.25pt] {} (.child anchor)\forestoption{edge label}; }, before typesetting nodes={ if n=1 {insert before={[,phantom]}} {} }, fit=band, before computing xy={l=15pt}, if n children=0{if n=1{yshift=-1.5cm}{}}{} } [text1 [text1.1 [text1.1.1] [text1.1.2] [text1.1.3] ] [text1.2 [text1.2.1] [text1.2.2] ] ] \end{forest}

Sandy G
  • 42,558