4

I'm following the tutorial/MWE provided at this link : http://www.texample.net/tikz/examples/filesystem-tree/

I would like to have to nodes at the same line, for example :

[MAIN]
|__________[UNDERMAIN1]____[PROPERTY1.1]_____[PROPERTY1.2]
|__________[UNDERMAIN2]____[PROPERTY2]
           |____________[UNDERUNDERMAIN2]_______[PROPERTY3]

So far I only found the way having the [properties] on below [undermain], but not at the same line.

Thank you in advance for your help.

Header12
  • 639

1 Answers1

2

The easiest to do this is to add the property nodes later to a named node.

The solution consists of the keys

  • property direction,
  • properties,

and the styles

  • every property and
  • every property edge.

After the tree has been built, the properties are used via late options.

Code

\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{trees,positioning}
\makeatletter
\tikzset{
  property direction/.initial=mid right,
  properties/.style={
    append after command={
      \pgfextra\let\qrr@tikzlastnode\tikzlastnode\endpgfextra
      \foreach \pgf@temp[count=\qrr@tikz@fig@prop from 0] in {#1} {
        \pgfextra
          \ifnum\qrr@tikz@fig@prop=0
            \let\qrr@tikz@fig@suffix\pgfutil@empty
          \else
            \edef\qrr@tikz@fig@suffix{-\number\numexpr\qrr@tikz@fig@prop-1\relax}%
          \fi
        \endpgfextra
        node [
          every property/.try,
          \pgfkeysvalueof{/tikz/property direction}=of \qrr@tikzlastnode\qrr@tikz@fig@suffix,
          name=\qrr@tikzlastnode-\qrr@tikz@fig@prop] {\pgf@temp}
        edge[every property edge/.try] (\qrr@tikzlastnode\qrr@tikz@fig@suffix)
      }
    }
  }
}
\makeatother
\tikzset{
  every property/.style={
    thin,
    node distance=.25cm,
  },
  every property edge/.style={densely dotted,-}
}
\begin{document}
\begin{tikzpicture}[
  every node/.append style={draw=black,thick,anchor=west,text height=\heightof{A}, text depth=+0pt},
  selected/.style={draw=red,fill=red!30},
  optional/.style={dashed,fill=gray!50},
  grow via three points={one child at (0.5,-0.7) and two children at (0.5,-0.7) and (0.5,-1.4)},
  edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}
]
  \node (texmf) {texmf}
    child { node (doc) {doc} }
    child { node {fonts} }
    child { node {source}}
    child { node [selected] {tex}
      child { node {generic}}
      child { node [optional] {latex}}
      child { node {plain}}
    }
    child [missing] {}
    child [missing] {}
    child [missing] {}
    child {node {texdoc}};

    \path [late options={name=doc,properties={a,b,c}}];

    \path [late options={name=texmf-1,properties={d,e,f}}];
\end{tikzpicture}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821