5

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:

enter image description here

  • 1
    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. – R. Schumacher Apr 24 '15 at 2:13
  • 1
    @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
  • 1
    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
  • 1
    Have a look at this answer for some possibly interesting alternatives to trees. – cfr Apr 24 '15 at 3:40
7

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:

stepwise tree

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:

coloured tree

\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};
    }
  },
  my shading/.style={
    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
    [textlength1\\text2, my shading=blue
        [text1lenght2, my shading=green
        ]
        [asdsdsd, my shading=blue!50!green
            [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, my shading=purple
        [HelloWorld333]
        [text1leng [text1lengAcid]]
    ]
    [backPress, my shading=red
        [text1lengAcid]
    ]
    [Hello, my shading=magenta]
    [World11333, my shading=orange
        [HelloWorld333, stepwise={25pt}{-15pt}]
        [Jango]
        [text1leng [text1lengAcid]]
    ]
  ]
\end{forest}

\end{document}
2

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:

enter image description here

  • 1
    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

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.