0

I'm trying to make a diagram for a folder/file structure. The problem I have is there is a large number of files in subfolders which produces a really long diagram.

MWE:

\documentclass[border=5pt]{standalone}
\usepackage[edges]{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,
    forked edges,
    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},
  }  
[Main Folder
  [subfolder 1
    [subsubfolder 1
      [file
      ]
    ]
    [subsubfolder 2
      [file
      ]
    ]
    [file
    ]
 ]
 [subfolder 2
 ]
 [subfolder 3
 ]
 [subfolder 4
 ]
]
\end{forest}
\end{document}

Which produces:

enter image description here

Is there a way I can branch each top level subfolder horizontally and have the remaining structure within the subfolder be vertical like the diagram above? E.g.

diagram

UPDATE

Using @js bibra's answer I changed the line

grow'=0,

To:

where level=0{
    l sep'=0.1cm,
    s sep'=0.5cm,
}{
    grow'=0,
},

For reference my full diagram then looks like: enter image description here

This is quite close to what I would like to achieve. Is there a way to reduce the horizontal spacing and centre the branches relative to the parent?

  • Please have a look at https://tex.stackexchange.com/a/339891. One problem, though, is that you show the output of a gigantic tree, but the example here shows only a very small one. How can anyone proposing an answer check if it will satisfy your needs? –  Mar 26 '20 at 16:42
  • @Schrödinger'scat I could include the full tex for my actual diagram in the question but the example code I have included is enough to test if the layout works. If I included the full tex for the actual diagram I'd probably be told to cut it down. – Darth Vader Mar 27 '20 at 10:33

1 Answers1

2

Is this what you are looking for

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{shadows,arrows.meta}
\tikzset{
  parent/.style={align=center,text width=4cm,fill=gray!50,rounded corners=2pt},
  child/.style={align=center,text width=2.5cm,fill=gray!20,rounded corners=6pt},
  grandchild/.style={fill=white,text width=2.3cm}
}
\begin{document}
\begin{forest}
  for tree={%
    thick,
    drop shadow,
    node options={
      draw,
      font=\sffamily
    },
    edge={
      semithick,
      -Latex
    },
    where level=0{
      parent,
      l sep'=0.8cm,
      s sep'=1.0cm,
    }{
      folder,
      grow'=0,
    },
    where level=1{
      minimum height=1cm,
      child,
      l sep=7.5mm,
      for descendants={%
        grandchild,
        minimum height=0.6cm,
      },
      for children={
        before computing xy={s+=5mm},
      }
    }{},
  }
  [\large Long text with line break%
    [\textbf{Test 1} \\ with a lot of subtext%
      [Topic]
      [Long topic with line break]
      [Topic]
    ]
    [\textbf{Test 2} \\ with a lot of subtext%
      [Topic]
      [Long topic with line break]
      [Topic]
    ]
    [\textbf{Test 3} \\ with a lot of subtext%
      [Topic]
      [Long topic with line break]
      [Topic]
    ]
    [\textbf{Test 4} \\ with a lot of subtext%
      [Topic]
      [Long topic with line break]
      [Topic]
    ]
  ]
\end{forest}
\end{document}
js bibra
  • 21,280
  • Thanks for the help, please see the update to my question. – Darth Vader Mar 26 '20 at 15:09
  • (+1) Remark for other users: I used this code in ran into a problem, see https://tex.stackexchange.com/questions/588018 for details. – Dr. Manuel Kuehner Mar 19 '21 at 17:47
  • If you based this answer on other answers or code, please can you link to your sources? This style of diagram has a frustrating history on this site in which the same question comes up time and again, but with no link back to the original sources. Or were you stuck with reinventing the wheel, too? (That is, its history is frustrating to me. I'm not claiming a general attitude!) – cfr Jul 25 '23 at 01:17