3

I followed the forest based solution of this post Making a (simple) directory tree to create a directory structure. Right to each file and name I want to add its full path. Full paths should also be left aligned. I came up with this dirty solution:

\documentclass{standalone}
\usepackage{forest}
\usetikzlibrary{positioning}
\begin{document}
\begin{forest}
  for tree={
    font=\ttfamily,
    grow'=0,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    s sep=6pt,
    inner sep=0pt,
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) +(6pt,0) |- (.child anchor)\forestoption{edge label};
    },
    before typesetting nodes={
      if n=1
      {insert before={[,phantom]}}
      {}
    },
    fit=band,
    before computing xy={l=5mm},
  }
  [a,name=a
    [b
      [c
        [d]
      ]
    ]
    [e
      [f]
      [b]
    ]
  ]
  %
  \node[right of=a,node distance=2cm] (desc) {\tt /a};
  \node[below=13pt of desc.west,anchor=west] (desc) {\tt /a/b};
  \node[below=13pt of desc.west,anchor=west] (desc) {\tt /a/b/c};
  \node[below=13pt of desc.west,anchor=west] (desc) {\tt /a/b/c/d};
  \node[below=12pt of desc.west,anchor=west] (desc) {\tt /a/e};
  \node[below=13pt of desc.west,anchor=west] (desc) {\tt /a/e/f};
  \node[below=13pt of desc.west,anchor=west] (desc) {\tt /a/e/b};
\end{forest}

\end{document}

That displays like this:

example tree

It looks ok, but I would like to come up with a clean solution that avoids hard-coding distances between full paths.

qouify
  • 135
  • 3

1 Answers1

1

I suggest simplifying your tree somewhat by using forked edge, with fork sep=0pt. (Note, this requires \usepackage[edges]{forest}.) I included each path description as a new child node, then used if n children=0{no edge, tier=desc}{l-=4mm} to prevent those last edges from being drawn and keep them aligned in the l dimension (which is what tier is used for). If n children≠0 then the l dimension is shortened by 4mm. You could also shorten (by the same or different amount) if you want the path description closer to the tree.

enter image description here

\documentclass{article}
\usepackage[edges]{forest}

\begin{document} \begin{forest} for tree={ font=\ttfamily, grow'=0, anchor=west, calign=first, s sep=6pt, inner sep=0pt, forked edge, fork sep=0pt, l sep=3mm, if n children=0{no edge, tier=desc}{l-=4mm} } [a [/a] [b [/a/b] [c [/a/b/c] [d [/a/b/c/d] ] ] ] [e [/a/e] [f [/a/e/f] ] [b [/a/e/b] ] ] ] \end{forest} \end{document}

Sandy G
  • 42,558