为文件结构添加描述

为文件结构添加描述

我想在我的文档中添加一个文件结构,并能够为每个目录/文件添加描述。从另一个问题我得到了这样的文件结构:

\usepackage{forest}

\begin{document}
\begin{forest}
    for tree={
        font=\ttfamily,
        grow'=0,
        child anchor=west,
        parent anchor=south,
        anchor=west,
        calign=first,
        edge path={
            \noexpand\path [draw, \forestoption{edge}]
            (!u.south west) +(7.5pt,0) |- node[fill,inner sep=1.25pt] {} (.child anchor)\forestoption{edge label};
        },
        before typesetting nodes={
            if n=1
            {insert before={[,phantom]}}
            {}
        },
        fit=band,
        before computing xy={l=15pt},
    }
    [text1
        [text1.1
            [text1.1.1 ... Here goes a description that could be multiple lines long]
            [some\_random\_file.txt ... This description is not aligned with the description above]
        ]
    ]
\end{forest}
\end{document}

我的方法有两个问题(只添加三个点然后添加描述)

首先,当描述太长时,它只会继续这一行,而不是进入下一行。

第二个是描述不一致。我尝试使用,\tabto但似乎不起作用。

有谁知道如何解决这些问题或知道如何让它看起来更美观吗?

答案1

像这样?

在此处输入图片描述

\documentclass{article}
    \usepackage{justtrees}% v 0.07
    \usetikzlibrary{arrows.meta}
    \useforestlibrary{edges}
    \forestapplylibrarydefaults{edges}

\begin{document}
{
\tikzset{lbl/.style={text width=16em, align=left,
                     xshift=12pt, yshift=1ex, inner ysep=0pt,
                     font=\linespread{0.84}\selectfont,
                     anchor=north west}}

\begin{forest}
    for tree={
        font=\ttfamily,
        anchor=west,
        grow'=0,
        s sep+=13pt,  % 7pt if descritons has only 2 lines
        calign=first,
        edge path={
            \noexpand\path [draw, \forestoption{edge}]
            (!u.south west) +(7.5pt,0) |- node[fill,inner sep=1.25pt] {} (.child anchor)\forestoption{edge label};
        },
        before typesetting nodes={
            if n=1
            {insert before={[,phantom]}}
            {}
        },
        fit=band,
        before computing xy={l=15pt},
    }
    [text1
        [text1.1,
            [text1.1.1, name=A]
            [some\_random\_file.txt,name=B]
        ]
    ]
\node[lbl] at (A-|B.east) {Here goes a description that could be multiple lines long long long long long long long long long long};
\node[lbl] at (B.east)    {This description is not aligned with the description above};
\end{forest}

\end{document}

注意:此解决方案需要一些手动调整。如果您的描述长于或短于三行,则需要进行s sep+相应更改(增加/缩短)。

相关内容