19

I would like to draw a picture that reflects some file structure. Below code works almost as expected. I need to adjust the connections between nodes so they don't start from the center of the bottom of the parent node but from near the left bottom corner.

How can I do this?

Code:

\documentclass[11pt, oneside]{article}
\usepackage{tikz}                           % super package for complex and awesome drawing

\begin{document}

\usetikzlibrary{trees}
\tikzstyle{every node}=[draw=black,thick,anchor=west,inner sep=2pt,minimum size=1pt]
\tikzstyle{selected}=[draw=cyan,fill=cyan!30]
\begin{tikzpicture}[
  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 {MainFolder-\{version\}}
    child { node [label={[xshift=6.0cm, yshift=-0.58cm, color=gray] Documentation for developers}] {References and Documentation/}
        child { node [draw=none] {main.html} }
        child { node {reference/}
            child { node [draw=none] {...}}
        }
        child [missing] {}
    }
    child [missing] {}
    child [missing] {}
    child [missing] {}
    child { node {release/}
        child { node [draw=none] {libAwesome.a} }
        child { node [draw=none] {libAwesome.dylib} }
    };
\end{tikzpicture}
\tikzstyle{every node}=[] % resets borders of tables
\tikzstyle{selected}=[] % resets selected

\end{document}  

Ouput:

enter image description here

Ideal:

enter image description here

Any help is appreciated.

18

You have to set

  • the start of the edge from parent path
    • parent anchor=south west (is going to be saved in \tikzparentanchor)
    • + .4cm to the right
    • child anchor (\tikzchildanchor) need not to be set as the |- path operator takes care of that (the default .center anchor has the same y value as .west);
  • and the start of the growth function (grow via three points)
    • growth parent anchor=west
  • and the end of the growth function
    • every child node/.style={anchor=west}

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{trees,calc}
\begin{document}
\tikzset{
    every node/.style={
        draw=black,
        thick,
        anchor=west,
        inner sep=2pt,
        minimum size=1pt,
    }
}
\begin{tikzpicture}[
    grow via three points={
        one child at (0.8,-0.7) and two children at (0.8,-0.7) and (0.8,-1.4)
    },
    edge from parent path={
        ($(\tikzparentnode\tikzparentanchor)+(.4cm,0pt)$) |- (\tikzchildnode\tikzchildanchor)
    },
    growth parent anchor=west,
    parent anchor=south west,% = \tikzparentanchor
%   child anchor=west,%        = \tikzchildanchor
%   every child node/.style={anchor=west}% already in "every node"
  ]
  \node {MainFolder-\{version\}}
    child { node [label={[xshift=6.0cm, yshift=-0.58cm, color=gray] Documentation for developers}] {References and Documentation/}
        child { node [draw=none] {main.html} }
        child { node {reference/}
            child { node [draw=none] {\ldots}}
        }
        child [missing] {}
    }
    child [missing] {}
    child [missing] {}
    child [missing] {}
    child { node {release/}
        child { node [draw=none] {libAwesome.a} }
        child { node [draw=none] {libAwesome.dylib} }
    };
\end{tikzpicture}
\end{document}

Output

enter image description here

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.