# How to set distance between individual siblings in a tikz-qtree tree?

I have made this tree for my research project. I've just renamed all attributes for this question. You can see in the picture below that siblings on the top are very congested and the picture overall looks really bad. How can I create distance between individual siblings for a particular level? Is there any other way to beautify this diagram, to make it more like professional one?

Code:

\documentclass[12pt]{article}

\usepackage[a4paper]{geometry}% just to demonstrate the effects

\usepackage{graphicx}
\usepackage{qtree}

%\usetikzlibrary{arrows}
\usepackage{tikz-qtree}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

%\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{arrows}

\begin{document}

\resizebox{1\linewidth}{!}{%
\begin{tikzpicture}[grow=right]
\tikzset{every tree node/.style={align=center}}
\tikzset{level distance=90pt}
\tikzset{level 1/.style={sibling distance=-50pt}}
\tikzset{edge from parent/.append style={thick,-stealth}}
%\tikzset{execute at begin node=\strut}
\Tree[.text1length1
[.textlength1\\text2
[.text1lenght2 ]
[.asdsdsd
[.asdasdsd
[.text1leng
[.text1lenght2 ]
[.asdasdsd [.text1leng [.text1lengAcid ] ] ]
]
[.text1leng [.text1lengAcid ]]
] %asdasdsd
[.asdEERER
[.text1lenght2 ]
[.asdasdsd [.text1leng [.text1lengAcid ] ] ]
]
[.text1lenght2 ]
] %asdsdsd
[.aASDASD
[.text1leng [.text1lengAcid ]
[.ASDERESSD
[.text1lenght2 ]]
[.asdsdsd
[.text1lenght2 ]
[.asdEERER
[.text1lenght2 ]
[.asdasdsd [.text1leng [.text1lengAcid ] ] ]
]
[.asdasdsd
[.text1leng ][.text1lenght2 ]
[.text1leng [.text1lengAcid ] ]
]
]
[.aASDASD
[.text1leng [.text1lengAcid ] ]
[.ASDERESSD
[.text1lenght2 ]
[.asdsdsd
[.text1lenght2 ]
[.asdEERER [.text1lenght2 ] ]
]
]
]
]
]
]
[.HelloWorld111
[.HelloWorld333 ]
[.text1leng [.text1lengAcid ] ]
]
[.backPress
[.text1lengAcid ]
]
[.Hello ]
[.World11333
[.HelloWorld333 ]
[.Jango ]
[.text1leng [.text1lengAcid ] ]
]
]
\end{tikzpicture}
}

\end{document}


Output:

• This item tex.stackexchange.com/questions/100851/… may have several solutions for you. The discussion on how to do manual spacing in a qtree is appropriate if you just have one tree. If you have many trees then the forest solution might be better. Apr 24 '15 at 2:13
• @R.Schumacher Could you say a little bit more about how the OP might use the solutions there? The question there seems to be a rather different one.
– cfr
Apr 24 '15 at 3:11
• Have you considered using something like schemata instead? Note that I am a huge fan of trees, especially in forest. But I wonder whether that is really your best option here. It is, however, difficult to judge without some idea of the topic.
– cfr
Apr 24 '15 at 3:15
• If you have a full TeX installation, forest should already be installed. If not CTAN is the place for all things TeX. schemata is billed as a package for typesetting philosophy and theology from the Scholastic era, but I looked at it the other day and couldn't see why it was described in terms of such a niche market. (I would have assumed it of no interest to me if somebody hadn't explicitly said how useful they found it.) So don't be put off by the summary description.
– cfr
Apr 24 '15 at 3:23
• Have a look at this answer for some possibly interesting alternatives to trees.
– cfr
Apr 24 '15 at 3:40

Here's a variation of the tree you produced using forest. Note that part of the problem here is that I have no idea how to hyphenate something like text1lenght2. I've therefore assumed that these cannot be hyphenated. If they could, you could create a nicer result.

To avoid allowing the tree to expand beyond reason, I've therefore defined a style stepwise={}{} which will take the path between parent and child in steps. The standard path moves in a horizontal/vertical fashion rather than flying straight as the eagle, because this reduces the chances that the edge will collide with a node.

Note that if you use a south-growing tree, none of this is required as the collisions do not occur.

The resulting tree is relatively compact: it will fit on landscape A4 without scaling. As you probably know, scaling diagrams should be avoided if at all possible.

Here's the result:

Here's the code:

\documentclass[border=5pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{forest}
\begin{document}
\tikzset{>=latex}

\forestset{
stepwise/.style n args=2{
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) |- +(#1,#2) |- (.child anchor)\forestoption{edge label};
}
}
}

\begin{forest}
for tree={
edge=->,
grow=east,
align=left,
child anchor=west,
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) |- (.child anchor)\forestoption{edge label};
},
font=\sffamily
}
[text1length1
[textlength1\\text2
[text1lenght2
]
[asdsdsd
[asdasdsd, stepwise={30pt}{-20pt}
[text1leng
[text1lenght2]
[asdasdsd [text1leng [text1lengAcid]]]
]
[text1leng [text1lengAcid]]
] %asdasdsd
[asdEERER
[text1lenght2]
[asdasdsd [text1leng [text1lengAcid]]]
]
[text1lenght2]
] %asdsdsd
[aASDASD
[text1leng [text1lengAcid]
[ASDERESSD
[text1lenght2]]
[asdsdsd
[text1lenght2]
[asdEERER
[text1lenght2]
[asdasdsd [text1leng [text1lengAcid]]]
]
[asdasdsd
[text1leng ][text1lenght2]
[text1leng [text1lengAcid]]
]
]
[aASDASD
[text1leng [text1lengAcid]]
[ASDERESSD
[text1lenght2]
[asdsdsd
[text1lenght2]
[asdEERER [text1lenght2]]
]
]
]
]
]
]
[HelloWorld111
[HelloWorld333]
[text1leng [text1lengAcid]]
]
[backPress
[text1lengAcid]
]
[Hello]
[World11333
[HelloWorld333, stepwise={25pt}{-15pt}]
[Jango]
[text1leng [text1lengAcid]]
]
]
\end{forest}

\end{document}


EDIT Probably better with sans text, which also makes the tree more compact horizontally.

Not recommended for all contexts, but a dynamically shaded tree is also a possibility:

\documentclass[border=5pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{forest}
\begin{document}
\tikzset{>=latex}

\forestset{
stepwise/.style n args=2{
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) |- +(#1,#2) |- (.child anchor)\forestoption{edge label};
}
},
for tree={
text/.wrap pgfmath arg={black!##1!#1}{10*level()},
edge/.wrap pgfmath arg={->, draw=black!##1!#1}{10*level()},
},
},
}

\begin{forest}
for tree={
edge=->,
grow=east,
align=left,
child anchor=west,
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) |- (.child anchor)\forestoption{edge label};
},
font=\sffamily
}
[text1length1
]
[asdasdsd, stepwise={30pt}{-20pt}
[text1leng
[text1lenght2]
[asdasdsd [text1leng [text1lengAcid]]]
]
[text1leng [text1lengAcid]]
] %asdasdsd
[asdEERER
[text1lenght2]
[asdasdsd [text1leng [text1lengAcid]]]
]
[text1lenght2]
] %asdsdsd
[aASDASD
[text1leng [text1lengAcid]
[ASDERESSD
[text1lenght2]]
[asdsdsd
[text1lenght2]
[asdEERER
[text1lenght2]
[asdasdsd [text1leng [text1lengAcid]]]
]
[asdasdsd
[text1leng ][text1lenght2]
[text1leng [text1lengAcid]]
]
]
[aASDASD
[text1leng [text1lengAcid]]
[ASDERESSD
[text1lenght2]
[asdsdsd
[text1lenght2]
[asdEERER [text1lenght2]]
]
]
]
]
]
]
[HelloWorld333]
[text1leng [text1lengAcid]]
]
[text1lengAcid]
]
[HelloWorld333, stepwise={25pt}{-15pt}]
[Jango]
[text1leng [text1lengAcid]]
]
]
\end{forest}

\end{document}


To make the picture look better, I finally figured out how to install forest. I opened package manager of MikTex from StatMenu->Programs->MikTex->PackageManger. I installed forest. From installation directory, I copied forest.sty and pasted in the current working directory. Using forest, this is how the above diagram looks like.

Code:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{forest}

\begin{document}
\tikzset{>=latex}

\resizebox{0.8\textwidth}{!}{%
\begin{forest} for tree={align=center,edge=->,grow=east}
[text1length1
[textlength1\\text2
[text1lenght2 ]
[asdsdsd
[asdasdsd
[text1leng
[text1lenght2 ]
[asdasdsd [text1leng [text1lengAcid ] ] ]
]
[text1leng [text1lengAcid ]]
] %asdasdsd
[asdEERER
[text1lenght2 ]
[asdasdsd [text1leng [text1lengAcid ] ] ]
]
[text1lenght2 ]
] %asdsdsd
[aASDASD
[text1leng [text1lengAcid ]
[ASDERESSD
[text1lenght2 ]]
[asdsdsd
[text1lenght2 ]
[asdEERER
[text1lenght2 ]
[asdasdsd [text1leng [text1lengAcid ] ] ]
]
[asdasdsd
[text1leng ][text1lenght2 ]
[text1leng [text1lengAcid ] ]
]
]
[aASDASD
[text1leng [text1lengAcid ] ]
[ASDERESSD
[text1lenght2 ]
[asdsdsd
[text1lenght2 ]
[asdEERER [text1lenght2 ] ]
]
]
]
]
]
]
[HelloWorld111
[HelloWorld333 ]
[text1leng [text1lengAcid ] ]
]
[backPress
[text1lengAcid ]
]
[Hello ]
[World11333
[HelloWorld333 ]
[Jango ]
[text1leng [text1lengAcid ] ]
]
]
\end{forest}
}
\end{document}


Picture:

• If you installed the package, you don't need to copy it to your working directory. In fact, it would be better not to do that as you'll miss out on any bug fixes or updates. I'm not clear whether this is a satisfactory solution for you or whether you still have a question. If this is part of your question, you should edit your question and add it rather than posting it as an answer. Could you clarify? Does this answer solve the problem for you?
– cfr
Apr 24 '15 at 22:58