森林的标记线

森林的标记线

我想构建一个tikz可视化目录结构的图表,并允许我为每个文件夹添加描述。这些描述应该对齐以吸引眼球。我最接近的方法是创建两个单独的forest图表,但对齐不起作用,即使我inner ysep在选项中手动指定对齐。

顺便问一下,有没有办法自动生成左箭头,而不是每次都将其作为标签的一部分输入?

梅威瑟:

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

输出

答案1

您可以为想要连接到箭头的节点提供别名,然后只需添加箭头即可。(尽管手动添加别名似乎不必要地复杂化。但它可能是查看哪些附加信息连接到哪个节点的最简单方法。)

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

在此处输入图片描述

相关内容