![如何控制森林环境中父节点与第一个子节点之间的垂直空间](https://linux22.com/image/464049/%E5%A6%82%E4%BD%95%E6%8E%A7%E5%88%B6%E6%A3%AE%E6%9E%97%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%88%B6%E8%8A%82%E7%82%B9%E4%B8%8E%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%AD%90%E8%8A%82%E7%82%B9%E4%B9%8B%E9%97%B4%E7%9A%84%E5%9E%82%E7%9B%B4%E7%A9%BA%E9%97%B4.png)
根据答案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}