# tree list in a table

I would like to put a tree list into a table environment. Smth. like:

+--------------------------+---------------------------+-------------+
+--------------------------+---------------------------+-------------+
| / 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 |
+--------------------------+---------------------------+-------------+


I know about dirtree package, but it it possible to arrange dirtree data in that way?

P.S.: I received multiple answers to this question, which solve the problem. I personally found the accepted answer more appropriate in my case. But here are also answers how to achieve the requested functionality with dirtree package. Therefore I encourage everyone to read all answers to find the best possible solution.

-
Welcome to tex.sx! Note that you don't have to (and shouldn't) sign with your name since it automatically appears in the lower right corner of your post. – Hendrik Vogt Jan 11 '11 at 15:04

Here an example how you can mimic that with pure table environment. But you don't have connections between sub-items.

Hope that helps anyway.

\begin{table}[p]
\begin{center}
\caption{Some caption of your table} \label{tab:trendtable}
\begin{tabular}{lll}
\midrule[1pt]
\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}

-
While this seems to have been accepted by the questioner, it doesn't use dirtree, and since the answer posted by Yiannis (along with my comment) actually solves the problem with dirtree it should be preferred as an answer. – Alan Munn Jan 11 '11 at 16:30
@Alan: Please see my comment in the post of Yiannis, regarding your answer. IMO this answer deserves a + point! – dusha Jan 11 '11 at 16:43
Instead multicolumn{1}{c} {Heading 2} it should be \multicolumn{1}{c} {Heading 2}! – cmur2 May 31 '13 at 17:13

You can use dirtree within a table, just enclose the mark-up within a minipage and be careful with the stops at the end of the lines! Here is a minimal example:

\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}


This will produce an output as requested (two columns) the third is trivial! For anything more fancy I would use a graphics package such as TikZ or pstricks. This sort of layout IMHo is better produced using, just minipages and or specially constructed environments. Nevertheless dirtree is a great package and one can use it for all sorts of different problems.

-
Thanks for the answer. But unfortunately that example generates 2 dirtrees side-by-side. I would like to have just usual data associated with each dirtree item, but this data should be aligned in the table. It is possible that I might have 3 or more columns. You can think of it as some kind of a TreeListView control: codeproject.com/KB/list/treelistview.aspx – dusha Jan 11 '11 at 15:10
@Dusha: Make an extra \dirtree for each of your subsequent columns, and use \DTsetlength with everything set to 0. (or if you still want indenting for the levels, set the width parameter.) – Alan Munn Jan 11 '11 at 15:46
Alan thanks a lot. I did not explicitly require to use dirtree. I just stated that I know about that package. Anyway I find the accepted answer easier to use and maintain. It is more visual to have related items on one line, instead of counting the lines of subsequent dirtrees just to find out the relation. If you gave a minus point to the accepted answer, I find it a petty, since I really like the simplicity of the idea. – dusha Jan 11 '11 at 16:41
@dusha See the edit above. – Yiannis Lazarides Jan 11 '11 at 16:45
@Alan Munn Thanks for the tip! +1 – Yiannis Lazarides Jan 11 '11 at 16:45

Here is a direct solution (based entirely off of Yiannis's answer) which solves the problem.

\documentclass{article}
\usepackage{dirtree,array}
\setlength{\extrarowheight}{3pt}
\begin{document}
\begin{tabular}{|l|l|l|}
\hline
\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{%
.4 .
}\end{minipage}
&
\DTsetlength{0pt}{0pt}{0pt}{0pt}{0pt}
\begin{minipage}{4cm}\dirtree{%
.3 Still more.
.4 And more.
}\end{minipage}\\
\hline
\end{tabular}
\end{document}
&
\DTsetlength{0pt}{0pt}{0pt}{0pt}{0pt}
\begin{minipage}{6cm}\dirtree{%

Thanks for posting your answer using \DTsetlength, it is a very clean solution and programmabel, i.e one can define \addline{} and do a row etc that can work on both sides. – Yiannis Lazarides Jan 11 '11 at 16:49