![在森林树节点右侧添加附加标签](https://linux22.com/image/364334/%E5%9C%A8%E6%A3%AE%E6%9E%97%E6%A0%91%E8%8A%82%E7%82%B9%E5%8F%B3%E4%BE%A7%E6%B7%BB%E5%8A%A0%E9%99%84%E5%8A%A0%E6%A0%87%E7%AD%BE.png)
我正在使用 forest 包绘制一棵树,该树概述了由相互继承的类排列实现的根接口。我仍然需要处理图形布局,但我认为我已经掌握了基础知识:
\documentclass{minimal}
\usepackage{tikz}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
my label/.style={
label={[font=\ttfamily]right:{#1}},
},
for tree={
folder,
font=\ttfamily,
s sep=0.1cm,
grow'=0,
edge={line width=1pt},
fit=band,
},
[interface
[base class
[abstract intermediate class
[implementation class 1]
[implementation class 2]
[implementation class 3]
]
[different class
[implementation class 4]
]
]
]
\end{forest}
\end{document}
我需要向树中添加另一组描述。每个类都有一个与之关联的文本,我需要在右侧的树旁边用不同的字体显示该文本。我希望将文本显示在与构成树节点的技术类名相同的高度,但我希望水平对齐描述以实现“更干净”的外观。这是一个模型,其中添加了一些线条以显示预期的对齐方式:
答案1
像这样吗?
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
my label/.style={
label={[font=\ttfamily]right:{#1}},
},
for tree={
folder,
font=\ttfamily,
s sep=0.1cm,
grow'=0,
edge={line width=1pt},
fit=band,
},
write me/.style={
tikz+={
\node [anchor=mid west, red] at (.mid -| write me coord) {#1};
},
},
tikz+={
\coordinate (write me coord) at (current bounding box.east);
}
[interface, write me=tag 1
[base class, write me=tag 2
[abstract intermediate class, write me=tag 3
[implementation class 1, write me=tag Z]
[implementation class 2, write me=tag D]
[implementation class 3, write me=tag T]
]
[different class, write me=tag S
[implementation class 4, write me=tag W]
]
]
]
\end{forest}
\end{document}