根据答案https://tex.stackexchange.com/a/270761/278762来自@GonzaloMedina。我如何控制y
下图所示的垂直空间
代码:
\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}
输出:
答案1
如果您想要更改的所有子项的间距text1.1
,您只需更改s sep
:
[text1
[text1.1, s sep=1cm
[text1.1.1]
[text1.1.2]
[text1.1.3]
]
另一方面,如果您只想更改上面的间距text 1.1.1
,那么您可以yshift=
向节点添加:
[text1
[text1.1
[text1.1.1, yshift=-1.5cm]
[text1.1.2]
[text1.1.3]
]
如果要对所有x.x.1
节点执行此操作,可以将其添加到for tree
:
if n children=0{if n=1{yshift=-1.5cm}{}}{}
完整代码如下:
\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}