Home > tikz pgf > How to draw a tree with fixed node distances?

# How to draw a tree with fixed node distances?

January 7Hits:2

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}   


## Ideal:

Any help is appreciated.

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}



## Related Articles

• ### How to draw a tree with fixed node distances? January 7

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 c

• ### Drawing a tree where many nodes have the same child in TikZJune 8

I'm trying the draw a tree using the TikZ package, but I don't know how to draw a child node that has many parents. An example for that, is given by this picture My problem is how to draw the level 3. --------------Solutions------------- You can use

• ### Draw a tree with variable node numberJune 15

I would like to draw a tree in tex that is more like a sketch of a tree: It should contain variable node numbers. Important is, that the dots are contained in the tree drawn. Is that possible with an automated command? You see, since my painting skil

• ### Change node distance using a macro and include a label to the background next to the nodesJune 27

the picture doesn't fit onto an A4 page. So what I would like to change/add is: the node distance the font size a vertical text which groups nodes together a number infront of each node as the "step number" a bigger distance between the "gr

• ### How to use the node distance to offset the start and/or end of an arrow with TikZ?September 24

I want to draw an arrow where one of the end points is not actually attached to another node, and I want the length of the arrow to take into account the node distance of the node to which the arrow is attached. So I would like to be able to write so

• ### Draw Tikz Tree where level distance between multi-line nodes is constantMarch 26

I am drawing a tree with tikz, namely, using tikz-qtree-compat for simpler syntax. On the tree there can be nodes of different height but then branches become messy. I want to add an instruction where distance between the south point of a mother node

• ### Overriding node draw style inherited from every node style messes up positioningMarch 5

I have been trying to draw a tree with TikZ. All nodes should be circles, so I use the every node style. There are some additional labels on some nodes, which have to be exceptions. I have tried this: \documentclass{article} \usepackage{tikz} \usetik

• ### Draw randomized tree in TikZAugust 16

I am trying to draw a randomized tree using TikZ, that is, I'm looking for a macro \randtree{NN}{x} that attaches a randomized tree of maximum depth x to a node named NN. The nodes need not be visible or marked, I just want the lines. I did a bit of

• ### forest trees: rounded rectangle nodes overlapFebruary 23

I am drawing a tree with the help of the forest package. Some of my nodes use TikZ's rounded rectangle style (see manual p.458). However, the round sides of those nodes overlap. How do I fix that? \documentclass{standalone} \usepackage{forest} \begin

• ### How can I draw simple trees in LaTeX?November 16

I need to draw a tree, and constantly using dotty and including the PNGs is starting to be a pain. Is there a way to get LaTeX to draw it's own trees that doesn't involve learning an entirely new language like TikZ? --------------Solutions-----------

• ### Drawing a tree of gridsApril 3

I need to draw a game tree that is similar to the image below. Is there any way to do this using the Tikz package so that the grids can simply be added as nodes? --------------Solutions------------- TikZ doesn't have a node shape of this form. But si

• ### How do I draw a tree file structure?April 19

I'm looking for a (portable) software or script that would allow me to draw a specific file structure as a tree, in Windows XP. Much like DOS tree command, but "prettier" (as a graph or diagram) I already tried TreeSize but it doesn't suit my ne

• ### Aligning TikZ trees with other nodesApril 24

I would like to align a TikZ tree with another node by considering the tree as a whole like as if it was a node with anchors. For the moment I am only able to align the root node of the tree, not the whole tree itself. I use PGF 2.10. The following p

• ### Aligning multiple TikZ trees with other nodesMay 3

This question is directly related to Aligning TikZ trees with other nodes that I asked some time ago. By the time I asked the question I didn't realize that aligning multiple trees was not the same as aligning one tree. Indeed, the answer proposed by

• ### How to draw syntactical trees with parallel leafs for a natural language?May 6

I need to draw syntactical trees for a natural language. The problem is that I need all the leafs to be parallel. How the other nodes are sorted in relation to the other at the same depth is not important. In practical use you would a sentence at the

• ### Vertical line in binomial tree is ruining node coloringSeptember 9

How do I stop the dummy nodes from being colored? \documentclass{article} \usepackage{tikz} \usetikzlibrary{matrix,fit,backgrounds,calc} \begin{document} \begin{tikzpicture}[>=stealth,sloped] \matrix (tree) [% matrix of nodes, minimum size=1cm, colum

• ### Same node distance between levels in a tikz tree?November 21

I want to draw a tree using tikz, but I want the vertical distance between nodes in successive levels to be the same, regardless of the size of the node. For example: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[leve

• ### Drawing a tree with text on the edge concisely using TikZJanuary 22

I am new to TikZ and am trying to draw a tree with text only on the edge (action/line). I have managed to do it as seen below but I was hoping there was a more concise/legible way. \documentclass{article} \usepackage{tikz} \usetikzlibrary{trees} \beg

• ### How to draw a return arrow from node-3 to node-1March 14

Say I have a code to draw a flow chart, I want now a arrow from node 3 to node 1, how can I do that? 1<--| | | 2 | | | 3---- MWE \documentclass[class=article,border=0pt]{standalone} \usepackage{tikz} \usetikzlibrary{shapes,arrows} % Define block styl

• ### How to draw dotted line between two nodesApril 11

\begin{tikzpicture} \tikzset{grow'=right,level distance=60 pt} \Tree [.I \edge node[auto=left]{M};[.II \edge node[auto=left]{L};$3,3$ \edge node[auto=right]{R};[.$x,0$ ]] \edge node[auto=left]{B};[.II \edge node[auto=left]{L};$0,0$ \edge node[auto=ri