1

I would like to construct a tikz figure that visualizes a directory structure, and enables me to label each folder with a description. These descriptions should be aligned for visual appeal. The closest I've gotten is to create two separate forest diagram, but the alignment isn't working, even when I specify a inner ysep manually in the options.

As an aside, is there a way to automate the generation of the left arrows, rather than typing it as part of the label each time?

MWE:

\documentclass[border=5pt]{standalone}
\usepackage{forest}

\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}

\def\Size{4pt}
\tikzset{
    folder/.pic={
        \filldraw[draw=folderborder,top color=folderbg!50,bottom color=folderbg]
        (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt);  
        \filldraw[draw=folderborder,top color=folderbg!50,bottom color=folderbg]
        (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size);
    }
}

\forestset{is file/.style={
    edge path={
    \noexpand\path [draw, \forestoption{edge}]
    (!u.south west) +(7.5pt,0) |- (.child anchor) \forestoption{edge label};
}
}
}

\begin{document}

\begin{forest}
    for tree={
        font=\ttfamily,
        grow'=0,
        child anchor=west,
        parent anchor=south,
        anchor=west,
        calign=first,
        inner xsep=7pt,
        edge path={
            \noexpand\path [draw, \forestoption{edge}]
            (!u.south west) +(7.5pt,0) |- (.child anchor) pic {folder} \forestoption{edge label};
        },
        inner ysep=4pt,
        before typesetting nodes={
            if n=1
            {insert before={[,phantom]}}
            {}
        },
        fit=band,
        before computing xy={l=15pt},
    }  
    [{base}
    [{makefile}, is file
    ]
    [data
    [external
    ]
    [interim
    ]
    [processed
    ]
    [raw
    ]
    ]
    [docs
    ]
    [output
    [figures
    ]
    [paper
    ]
    [presentation
    ]
    [tables
    ]
    ]
    [src
    [analysis
    ]   
    [data
    ]
    [external
    ]
    [tools
    ]
    [visualization
    ]
    ]
    ]
\end{forest}
\begin{forest}
        for tree={
        grow'=0,
        child anchor=west,
        parent anchor=south,
        anchor=west,
        calign=first,
        inner xsep=7pt,
%       edge path={
%           \noexpand\path [draw, \forestoption{edge}]
%           (!u.south west) +(7.5pt,0) (.child anchor) \forestoption{edge label};
%       },
        no edge,
        inner ysep=4pt,
%       l=10pt,
%       l sep=20pt,     
        before typesetting nodes={
            if n=1
            {insert before={[,phantom]}}
            {}
        },
        fit=band,
        before computing xy={l=0pt},
    } 
[{$\leftarrow$ Everything should be in a self-contained directory}
[{$\leftarrow$ This allows you to run {\ttfamily make} commands}]
[{}
[{$\leftarrow$ Data from third party sources}]
[{$\leftarrow$ Intermediate data that has been transformed}]
[{$\leftarrow$ Final data sets used for analysis}]
[{$\leftarrow$ Original, immutable data dump}]
]
[{$\leftarrow$ Related literature and documentation}
]
[
{}
[{$\leftarrow$ Figures used in the draft and slides}]
[{$\leftarrow$ All the \texttt{.tex} files used to generate the draft}]
[{$\leftarrow$ All the \texttt{.tex} files used to generate the presentation}]
[{$\leftarrow$ Tables used in the draft and slides}]
]
[{}
[{$\leftarrow$ Source code for data analysis}]
[{$\leftarrow$ Scripts used to download or generate the data}]
[{$\leftarrow$ Code from third party sources}]
[{$\leftarrow$ Helper scripts}]
[{$\leftarrow$ Scripts for visualization of the data}]
]
]
\end{forest}
\end{document}

Output

Shffl
  • 237

1 Answers1

1

You can give the nodes you want to connect to arrows aliases and then just add the arrows.(Even though adding the aliases by hand my appeared to be unnecessarily complicates. it might be the easiest way to see which additional information connects to which node.)

\documentclass[border=5pt]{standalone}
\usepackage{forest}

\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}

\def\Size{4pt}
\tikzset{
    folder/.pic={
        \filldraw[draw=folderborder,top color=folderbg!50,bottom color=folderbg]
        (-1.05*\Size,0.2\Size+5pt) rectangle ++(.75*\Size,-0.2\Size-5pt);  
        \filldraw[draw=folderborder,top color=folderbg!50,bottom color=folderbg]
        (-1.15*\Size,-\Size) rectangle (1.15*\Size,\Size);
    },
}

\forestset{is file/.style={
    edge path={
    \noexpand\path [draw, \forestoption{edge}]
    (!u.south west) +(7.5pt,0) |- (.child anchor) \forestoption{edge label};
}
}
}
\begin{document}
\begin{forest}
    for tree={
        font=\ttfamily,
        grow'=0,
        child anchor=west,
        parent anchor=south,
        anchor=west,
        calign=first,
        inner xsep=7pt,
        edge path={
            \noexpand\path [draw, \forestoption{edge}]
            (!u.south west) +(7.5pt,0) |- (.child anchor) pic {folder} \forestoption{edge label};
        },
        inner ysep=4pt,
        before typesetting nodes={
            if n=1
            {insert before={[,phantom]}}
            {}
        },
        fit=band,
        before computing xy={l=15pt},
    }  
    [{base}
    [{makefile}, is file,alias=1
    ]
    [data,alias=2
    [external,alias=3
    ]
    [interim,alias=4
    ]
    [processed,alias=5
    ]
    [raw,alias=6
    ]
    ]
    [docs,alias=7
    ]
    [output
    [figures,alias=8
    ]
    [paper,alias=9
    ]
    [presentation,alias=10
    ]
    [tables,alias=11
    ]
    ]
    [src
    [analysis,alias=12
    ]   
    [data,alias=13
    ]
    [external,alias=14
    ]
    [tools,alias=15
    ]
    [visualization,alias=16
    ]
    ]
    ]
\begin{scope}[latex-]
\path (current bounding box.east)  + (1,0) coordinate (aux);    
\foreach \X [count=\Y] in {{Everything should be in a self-contained directory},
{This allows you to run {\ttfamily make} commands},
{Data from third party sources},
{Intermediate data that has been transformed},
{Final data sets used for analysis},
{Original, immutable data dump},
{Related literature and documentation},
{Figures used in the draft and slides},
{All the \texttt{.tex} files used to generate the draft},
{All the \texttt{.tex} files used to generate the presentation},
{Tables used in the draft and slides},
{Source code for data analysis},
{Scripts used to download or generate the data},
{Code from third party sources},
{Helper scripts},
{Scripts for visualization of the data}}
{
\draw (\Y) -- (\Y-|aux) node[right]{\X};}
\end{scope}
\end{forest}
\end{document}

enter image description here

  • Once I sow here solution for labeling three levels with use of package justtrees (from @cfr). You may find it useful. Nice answer (+1). – Zarko Feb 21 '20 at 07:29
  • @Zarko Thanks! You mean something like this one? –  Feb 21 '20 at 16:09
  • Yes. Now I remember this cfr answer: http://tex.stackexchange.com/questions/292725/ after which we have short discussion. – Zarko Feb 21 '20 at 16:33