有没有办法用forest
包将边锚定到多线节点的第一行?
在这个例子中,我希望中间的水平边缘指向123多行文本节点。
\documentclass[a4paper]{article}
\usepackage{geometry}% geometry or similar is needed for correct A4 layout
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={
folder,
grow'=0,
align=left
},
[ Top level
[ \textbf{ABC} ]
[ \textbf{123} Also some longer text.\\Also some longer text. Also some longer text. Also some longer text. Also some longer text.\\Also some longer text. Also some longer text. Also some longer text. Also some longer text.\\Also some longer text. Also some longer text.]
[ \textbf{ZYX} ]
]
\end{forest}
\end{document}
答案1
尽管解决方案有点不合理,但仍然可以完成。
首先,我添加了base=top
。在引擎盖后面,align=center
创建了一个表格环境并base=top
设置了t
垂直对齐。这让我们到达了第一行的底部。
为了绘制边缘,我手动设置了edge path
。我从样式中获取定义folder
(在中forest-lib-edges.sty
),并将第二个坐标调整为([yshift=.6ex].base west)
--- 因此基准向西并稍微向上移动(.6ex
根据您的喜好进行调整)。
\documentclass[a4paper]{article}
\usepackage{geometry}% geometry or similar is needed for correct A4 layout
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={
folder,
grow'=0,
align=left,
},
[ Top level
[ \textbf{ABC} ]
[ \textbf{123} Also some longer text.\\Also some longer text. Also some longer text. Also some longer text. Also some longer text.\\Also some longer text. Also some longer text. Also some longer text. Also some longer text.\\Also some longer text. Also some longer text.,
edge path'/.expanded={
([xshift=\forestregister{folder indent}]!u.parent anchor) |- ([yshift=.6ex].base west)
},
base=top,
]
[ \textbf{ZYX} ]
]
\end{forest}
\end{document}