0

I am trying to draw a directory tree. As the tree should visualize the structure of a MATLAB framework, i would love to represent the matlab files with the corresponding icon, e.g. enter image description here

I found the following code (which i dont really understand^^) on https://tex.stackexchange.com/a/405253

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[edges]{forest}
\definecolor{folderbg}{RGB}{124,166,198}
\definecolor{folderborder}{RGB}{110,144,169}
\newlength\Size
\setlength\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);
  },
  file/.pic={%
    \filldraw [draw=folderborder, top color=folderbg!5, bottom color=folderbg!10] (-\Size,.4*\Size+5pt) coordinate (a) |- (\Size,-1.2*\Size) coordinate (b) -- ++(0,1.6*\Size) coordinate (c) -- ++(-5pt,5pt) coordinate (d) -- cycle (d) |- (c) ;
  },
}
\forestset{%
  declare autowrapped toks={pic me}{},
  declare boolean register={pic root},
  pic root=0,
  pic dir tree/.style={%
    for tree={%
      folder,
      font=\ttfamily,
      grow'=0,
    },
    before typesetting nodes={%
      for tree={%
        edge label+/.option={pic me},
      },
      if pic root={
        tikz+={
          \pic at ([xshift=\Size].west) {folder};
        },
        align={l}
      }{},
    },
  },
  pic me set/.code n args=2{%
    \forestset{%
      #1/.style={%
        inner xsep=2\Size,
        pic me={pic {#2}},
      }
    }
  },
  pic me set={directory}{folder},
  pic me set={file}{file},
}
\begin{document}

\begin{forest}
  pic dir tree,
  pic root,
  for tree={% folder icons by default; override using file for file icons
    directory,
  },
  [folder
    [folder
      [matlab\_file.m, file
      ]
    ]
  ]
\end{forest}
\end{document}

enter image description here

This example does pretty much what i want, but i would like to change the symbol bevor the matlab_file.m to a custom symbol, like the picture above. Is there a way to get this done?

Originally i wanted to use the real icon as shown in the windows explorer. This symbol is a .ico file, which makes it a bit more difficult (as i suppose). I also couldn't uploade it here, cause the format is not supported. If someone whants to try it, the above picture can be downloaded as .ico here: http://www.iconarchive.com/download/i89749/alecive/flatwoken/Apps-Matlab.ico

But i will allready be happy if its working for .png pictures instead of .ico icons.

  • 1
    \tikzset{folder/.pic={\node{\includegraphics[width=...]{<some graphics>};}}}? – Schrödinger's cat Sep 10 '19 at 22:07
  • Yeah, that works ^^. Thanks! I tryed the same, but without the \node{}. – moro11 Sep 10 '19 at 22:17
  • What should we do with this question then? Do you want to self-answer (you were almost there)? – Schrödinger's cat Sep 11 '19 at 1:10
  • I answererd it now, i already thougt about that yesterday, but i don't want to "steal" your correct answer. – moro11 Sep 11 '19 at 14:12
1

According to Schrödinger's cat the solution is not to difficult, just replace the file/.pic={...}, line with

file/.pic={\node{\includegraphics[width=10pt]{<some graphics>}};},

Works perfectly fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.