3

I already found a similar question and thus know about the dirtree package. However, the result does not really look nice.

Also I'd like to put the tree in a figure environment and get it centered. This just does not work since only the text is centered, not the tree structure

\begin{figure}
  \centering
  \dirtree{%
    .1 spam.
    .2 ham.
    .2 eggs.
    .3 more spam.
    .3 dead parrots.
  }
  \caption[Directory Structure]{This is an example directory structure.}
  \label{fig:dir}
\end{figure}

Is there a better way to create file system visualizations?

Scolytus
  • 670
  • You will have to be more specific about what you would like the result to look like. – Andrew Swann Sep 13 '13 at 14:02
  • To me it just looks ugly. I know that's subjective. It also seems that it does not behave well in a figure environment, I'll add that to my question. – Scolytus Sep 13 '13 at 14:05

1 Answers1

4

Tikz trees are more complex but allow a fine tuning:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\tikzstyle{every node}=[draw=gray, very thick,anchor=west]
\begin{tikzpicture}[%
  grow via three points={one child at (0.5,-0.7) and %
  two children at (0.5,-0.7) and (0.5,-1.4)},%
  edge from parent path={(\tikzparentnode.south)%
  |- (\tikzchildnode.west)}]
\node {root}
    child { node {spam}}     
    child { node {ham}}
    child { node {eggs}
       child {node {more spam} }
      child { node {dead parrots}}}
    child [missing] {}              
    child [missing] {}              
    child [missing] {}              
    child { node {peanuts}};  
\end{tikzpicture}
\end{document}

MWE

Fran
  • 80,769