我想将树形列表放入表格环境中。例如:
+--------------------------+---------------------------+-------------+
| Heading 1 | Heading 2 | Heading 3 |
+--------------------------+---------------------------+-------------+
| / main-item | main item data | some info |
| +-- sub item 1 | sub item 1 data | some info 1 |
| | +-- sub sub item x | sub sub item 1.x data | some info x |
| | | | |
| +-- sub item 2 | sub item 2 data | some info 2 |
| +-- sub sub item y | sub sub item 2.y data | some info y |
+--------------------------+---------------------------+-------------+
我知道 dirtree 包,但是可以用这种方式排列 dirtree 数据吗?
PS:我收到了多个关于这个问题的答案,它们解决了这个问题。我个人认为接受的答案更适合我的情况。但这里也有关于如何使用 dirtree 包实现所请求功能的答案。因此,我鼓励大家阅读所有答案以找到最佳解决方案。
答案1
这里有一个示例,说明如何使用纯表格环境来模拟这种情况。但是子项之间没有连接。
无论如何,希望这能有所帮助。
\begin{table}[p]
\begin{center}
\caption{Some caption of your table} \label{tab:trendtable}
\begin{tabular}{lll}
\midrule[1pt]
\multicolumn{1}{c} {Heading 1} & \multicolumn{1}{c}{Heading 2} & \multicolumn{1}{c} {Heading 3} \\
\midrule[1pt]
\textbf{main-item} & main item data & some info\\
\hspace{0.2cm} sub item 1 & sub item 1 data & some info 1 \\
\hspace{0.4cm} sub sub item x & sub item 1.x & some info x \\
&&\\
\textbf{main-item 2} & ... & ...\\
\hspace{0.2cm} ... & ... & ... \\
\end{tabular}
\end{center}
\end{table}
答案2
您可以dirtree
在表格中使用,只需将标记放在小页面内,并注意行末的停止!这是一个最小的例子:
\documentclass{article}
\usepackage{dirtree}
\begin{document}
\begin{tabular}{|l|l|}
\begin{minipage}{4cm}\dirtree{%
.1 Engineering.
.2 Mechanical.
.3 Electrical.
.4 Electronics.
}\end{minipage}
& \begin{minipage}{4cm}\dirtree{%
.1 TeX.
.2 LaTeX.
.3 XeTeX.
.4 pdfLaTeX.
}\end{minipage}\\
\end{tabular}
\end{document}
根据评论进行编辑
\begin{tabular}{|l|p{3cm}|}
\begin{minipage}[t]{4cm}\dirtree{%
.1 Engineering.
.2 Mechanical.
.3 Electrical.
.4 Electronics.
}\end{minipage}
& Director A
\newline Director B
\newline Director C
\newline Director D\\
\end{tabular}
这将产生所需的输出(两列),第三列很简单!对于任何更花哨的东西,我会使用图形包,例如TikZ
或pstricks
。在我看来,这种布局最好使用 minipages 和或专门构建的环境来制作。尽管如此,这dirtree
是一个很棒的包,可以用它来解决各种不同的问题。
答案3
这是一个直接的解决方案(完全基于 Yiannis 的回答),可以解决问题。
\documentclass{article}
\usepackage{dirtree,array}
\setlength{\extrarowheight}{3pt}
\begin{document}
\begin{tabular}{|l|l|l|}
\hline
\multicolumn{1}{|c} {Heading 1} & \multicolumn{1}{|c|} {Heading 2} & \multicolumn{1}{c|}{Heading 3}\\
\hline
\begin{minipage}{4cm}\dirtree{%
.1 Engineering.
.2 Mechanical.
.3 Bio-mechanical.
.2 Electronics.
}\end{minipage}
&
\DTsetlength{0pt}{0pt}{0pt}{0pt}{0pt}
\begin{minipage}{6cm}\dirtree{%
.1 Stuff about engineering here.
.2 Stuff about Mechanical here.
.3 Stuff about biomechanical here.
.4 .
}\end{minipage}
&
\DTsetlength{0pt}{0pt}{0pt}{0pt}{0pt}
\begin{minipage}{4cm}\dirtree{%
.1 Comments.
.2 More comments.
.3 Still more.
.4 And more.
}\end{minipage}\\
\hline
\end{tabular}
\end{document}
&
\DTsetlength{0pt}{0pt}{0pt}{0pt}{0pt}
\begin{minipage}{6cm}\dirtree{%
.1 Stuff about engineering here.
.2 Stuff about Mechanical here.
.3 Stuff about Electrical here.
.4 .
}\end{minipage}
\end{tabular}
\end{document}