0

I've got this code from the user Gonzalo Medina here and it looks great, it's exactly what I want. However I would like to add a description of each folder that can be a rather long test, like for instance in the "config" node bellow.

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

\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}; }, before typesetting nodes={ if n=1 {insert before={[,phantom]}} {} }, fit=band, before computing xy={l=15pt}, }
[system [config: this text is sooooo long oh not it won't fit in the page help me please ] [lib [Access ] [Plugin ] ] [templates ] [tests ] ] \end{forest}

\end{document}

The result that I get is this: Problem with long descriptions

I would like that the text automatically went to a new line.

Thanks in advance!

1 Answers1

0

You can limit the width of the text. For example using text width=8cm

enter image description here

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

\begin{document}

\begin{forest}
    for tree={
        font=\ttfamily,
        text width=8cm,% added <<<<<<<<<<<<<<
        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};
        },
        before typesetting nodes={
            if n=1
            {insert before={[,phantom]}}
            {}
        },
        fit=band,
        before computing xy={l=15pt},
    }  
    [system
    [config: this text is sooooo long oh not it won't fit in the page help me please
    ]
    [lib
    [Access
    ]
    [Plugin
    ]
    ]
    [templates
    ]
    [tests
    ]
    ]
\end{forest}

\end{document}

UPDATE after follow up question.

This is another way:

b

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

\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};
        },
        before typesetting nodes={
            if n=1
            {insert before={[,phantom]}}
            {}
        },
        fit=band,
        before computing xy={l=15pt},
    }  
    [system
    [config: \parbox{7cm}{this text is sooooo long oh not it won't fit in the page help me please}% changed
    ]
    [lib
    [Access
    ]
    [Plugin
    ]
    ]
    [templates
    ]
    [tests
    ]
    ]
\end{forest}

\end{document}

Simon Dispa
  • 39,141