![水平树箭头未正确对齐](https://linux22.com/image/371414/%E6%B0%B4%E5%B9%B3%E6%A0%91%E7%AE%AD%E5%A4%B4%E6%9C%AA%E6%AD%A3%E7%A1%AE%E5%AF%B9%E9%BD%90.png)
我从多个地方获取了一些代码并将它们粘贴在一起,以显示文件夹及其底层文件夹的结构。我让它工作了,但是当我换到另一个 latex 模板时,树的最后一个箭头(从月到日)变得有点弯曲。
谁能告诉我为什么会发生这种情况以及如何解决这个问题?
代码:
\usepackage{forest}
\usetikzlibrary{arrows.meta}
{\small
\begin{figure}[h]
\centering
\begin{forest}
for tree={
grow=0,reversed, % tree direction
parent anchor=east,child anchor=west, % edge anchors
edge={->},outer sep=+1pt, % edge/node connection
rounded corners,minimum width=10mm,minimum height=8mm, % node shape
l sep=5mm % level distance
}
[Root folder
[Customer id
[Machine id
[Year
[Month
[Day]]]]]
]
\end{forest}
\caption{File hierarchy}
\label{fig:filehierarchy}
\end{figure}
}
结果:
答案1
这可能是因为只有最后一个节点有降部,即低于基线的字母(y
)。一种解决方法是添加font=\strut
到树设置中:
\documentclass{article}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{figure}[h]
\centering\small
\begin{forest}
for tree={
grow=0,reversed, % tree direction
parent anchor=east,child anchor=west, % edge anchors
edge={->},outer sep=+1pt, % edge/node connection
rounded corners,minimum width=10mm,minimum height=8mm,font=\strut, % node shape <-- added font=\strut
l sep=5mm % level distance
}
[Root folder
[Customer id
[Machine id
[Year
[Month
[Day]]]]]
]
\end{forest}
\caption{File hierarchy}
\label{fig:filehierarchy}
\end{figure}
\end{document}
答案2
最简单的解决方案可能是更改parent
和child
锚点以使用mid
,Ti钾Z 可用于对齐具有可变高度和深度的物体。
\documentclass{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{forest}
for tree={
grow'=0, % tree direction
parent anchor=mid east, % edge anchors
child anchor=mid west,
edge+={->}, % edge/node connection
outer sep=+1pt,
rounded corners, % node shape
minimum width=10mm,
minimum height=8mm,
l sep'=5mm % level distance <= no it isn't - it is the minimum level separation, which is not necessarily the dimension actually used
}
[Root folder
[Customer id
[Machine id
[Year
[Month
[Day]]]]]
]
\end{forest}
\end{document}
这避免了不必要地扩大节点,这在某些情况下可能是不可取的。