5

Possible Duplicate:
Drawing a directory listing a la the tree command in TikZ

Is there a way to configure the trees drawn by TikZ to have child nodes at the same level listed below each other? Basically, I want something similar to the output of the tree command in a Command Prompt.

\documentclass{article}
\usepackage{tikz}

\begin{document}

\section*{TikZ tree}
\begin{tikzpicture}
\node {toplevel} 
    child { node {Foo}
            child { node {foo} }
            child { node {bar} }
            child { node {baz} }
    }
    child { node {Bar}
        child { node {foo} }
        child { node {bar} }
        child { node {baz} }
    }
    child { node {Baz}
        child { node {foo} }
        child { node {bar} }
        child { node {baz} }
    };
\end{tikzpicture}

\section*{Desired tree structure}
\begin{verbatim}
toplevel
|-- Foo
|   |-- foo
|   |-- bar
|   `-- baz
|-- Bar
|   |-- foo
|   |-- bar
|   `-- baz
`-- Baz
    |-- foo
    |-- bar
    `-- baz
\end{verbatim}

\end{document}
Martin Heller
  • 11,391
  • There's been a very similar question that got a partial answer: http://tex.stackexchange.com/questions/23647/drawing-a-directory-listing-a-la-the-tree-command-in-tikz – Jake Nov 09 '11 at 10:47
  • Although the other one didn't get a full answer, this does feel like any answer to this would work for that and vice versa, so I'm tempted to vote to close as a duplicate and stick a flashing neon comment saying: "This is still unsolved" somewhere prominent. – Andrew Stacey Nov 09 '11 at 10:58
  • On the question itself (it's quite likely that I didn't see the original one), does it have to be done via a tree? It feels as though the vertical structure is so strong that I'd make that the controlling aspect, whereupon one could use grouping to adjust the horizontal spacing. – Andrew Stacey Nov 09 '11 at 11:00
  • There's also the dirtree package which is designed for these sorts of trees. In which case Making a (simple) directory tree is a duplicate. – Alan Munn Nov 09 '11 at 12:20
  • @Jake and Andrew Stacey: Sorry for the possible dublicate. I'm perfectly fine with closing this one and/or redirecting answers to the original. I just don't know how to do it. – Martin Heller Nov 09 '11 at 15:30
  • @Andrew Stacey: It does not have to be made with trees. It just seems to me to be a very natual choice of syntax in TikZ for this type of structure. I thought it might be possible to define sibling distance or level distance as a function of \tikznumberofchildren and \tikznumberofcurrentchild. – Martin Heller Nov 09 '11 at 15:35
  • @MartinHeller: Don't fret about the duplicate! That's often an indication of a good question - so good that someone's asked it before. As for the trees, I agree that it does feel natural. I'm just thinking around the idea, if you see what I mean. – Andrew Stacey Nov 09 '11 at 18:40
  • Just posted an answer at the other question (to keep them all together). – Andrew Stacey Nov 09 '11 at 21:28
  • @Andrew Stacey: Thank you for the answer! How do I mark this question as answered so that it does not get stuck in the "unanswered" category? – Martin Heller Nov 10 '11 at 07:45
  • It's already got three votes to "close as duplicate". As you're happy with that answer, a moderator would probably be happy to step in and cast the final vote(s). I'll flag it for moderator attention. – Andrew Stacey Nov 10 '11 at 07:49

0 Answers0