![横向森林的右侧表格](https://linux22.com/image/368118/%E6%A8%AA%E5%90%91%E6%A3%AE%E6%9E%97%E7%9A%84%E5%8F%B3%E4%BE%A7%E8%A1%A8%E6%A0%BC.png)
我正在尝试制作一张与我的森林中的最后一个链接相对应的表格。
我的森林看起来像这样:
\documentclass[12pt,a4paper,twoside]{report}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
edge path={
\noexpand\path[\forestoption{edge}](!u.parent anchor) -- +(5pt,0) |- (.child anchor)\forestoption{edge label};},
grow=0,
reversed, % tree direction
parent anchor=east,
child anchor=west, % edge anchors
anchor=west,
if n children=0{tier=word}{}
}
[\textbf{Output Devices}
[Visual
[Mobile
[Simple
[Google Cardboard]
[Google Daydream]
[Samsung Gear VR]
]
[Stand-alone]
]
[Wired
[Room]
[Seated]
]
]
[Haptic
[Body worn]
[Multi-sensory
[Sensics]
[FeelReal]
[Nirvana Mask]
]
]
]
\end{forest}
\end{document}
你有什么想法吗?任何帮助都将不胜感激。
答案1
假装。或者花一生去尝试维护无法维护的东西。
将每个终端节点设为单行表格,参照森林节点绘制单元格边框,分别添加表头等。
这是一个解决方案。根据单元格和标题内容,将单元格宽度尺寸调整为合适的尺寸。我将其用于1em
演示目的。
由于您没有在代码中提供任何标题内容,因此我添加了一个单行标题,其中包含英文字母表的前七个字母。如果您想要上方一行没有边框(如您的图片所示),只需添加另一个节点,并在上方添加另一个表格p0
。无需调整线条绘制,因为您不需要边框。
\documentclass[12pt,border=10pt]{standalone}
\usepackage[edges]{forest}
\usepackage{array}
\newcolumntype{C}{>{\centering\arraybackslash}p{1em}}
\usetikzlibrary{calc}
\begin{document}
\forestset{
declare count register=count us,
count us'=0,
}%
\begin{forest}
forked edges,
for tree={
grow'=0,
s sep'=0pt,
parent anchor=children,
child anchor=parent, % edge anchors
anchor=parent,
if n children=0{
!u.tier=word,
tier=terminus,
align=*{7}{C},
no edge,
inner sep=0pt,
count us'+=1,
name=p\foresteregister{count us},
}{}
}
[\textbf{Output Devices}
[Visual
[Mobile
[Simple
[Google Cardboard[x&&&&&&]]
[Google Daydream[x&&&&&&]]
[Samsung Gear VR[x&&&&&&x]]
]
[Stand-alone[&&x&&&&]]
]
[Wired
[Room[x&&&&&&]]
[Seated[x&&&&&&]]
]
]
[Haptic
[Body worn[x&&&&&&]]
[Multi-sensory
[Sensics[x&&&&&&]]
[FeelReal[x&&&&&&]]
[Nirvana Mask[x&&&&&&]]
]
]
]
\node [anchor=south west, inner sep=0pt] (p0) at (p1.north west) {\begin{tabular}{*{7}{C}}A&B&C&D&E&F&G\end{tabular}};
\draw (p0.north west) rectangle (p10.south east) ;
\foreach \i in {0,1,...,7} \draw ($(p0.north west)!\i/7!(p0.north east)$) -- ($(p10.south west)!\i/7!(p10.south east)$);
\foreach \i [remember=\i as \ilast (initially 0)] in {1,...,10} \draw ($(p\i.north west)!.5!(p\ilast.south west)$) -- ($(p\i.north east)!.5!(p\ilast.south east)$) ;
\end{forest}
\end{document}