Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a diagram in tikz-qtree like figure A, but I'd like something like figure B. Is it possible, to alter the properties of only one branch? (these figures were made with Dia and arrows are not important)

edit: (added my modified code, based on Alan Munn's answer)

\begin{center}
\begin{tikzpicture}[grow'=right,level distance=1.45in,sibling distance=.2in]

\tikzset{edge from parent/.style= 
{thick, draw, edge from parent fork right},
  every tree node/.style=
    {draw,minimum width=1.3in,text width=1.15in,align=center}
}
\Tree 
  [.parent
    [.child0
      grandchild0-0
      grandchild0-1
      [[.{grandchild0-2} 
        {greatgrandchild0} 
        {greatgrandchild0}
        {greatgrandchild0} 
        {greatgrandchild0}
      ]] 
      grandchild0-3
    ] 
    [.child1
      [.grandchild1-0 ] 
      [.grandchild1-1 ] 
    ] 
  ]
\end{tikzpicture}
\end{center}
share|improve this question
4  
It would be helpful to post the TikZ code that you have already in a complete compilable document. –  Alan Munn May 8 '12 at 18:44
    
@Greg Your second edit is a perfectly acceptable solution (especially for a one-off diagram) so instead of editing your question you should post it as a solution. It's fine to post answers to your own questions (and even accept them (although there's a 2 day waiting period for that, I think). –  Alan Munn May 8 '12 at 21:29
    
Yeah, I edited because I couldn't post own topic. Now, I've just I done. It was a solution to that issue. The funny thing is, atfer 2 days requirements have changed, so finally I will rahter use qtree. :D Thanks for your help. :) –  Greg May 11 '12 at 15:55

3 Answers 3

You can add extra brackets around a node to extend its branch:

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees} % this is to allow the fork right path

\begin{document}

\begin{tikzpicture}[level distance=1.25in,sibling distance=.15in,scale=.75]
\tikzset{edge from parent/.style= 
            {thick, draw,
                edge from parent fork right},every tree node/.style={draw,minimum width=1in,text width=1in, align=center},grow'=right}
\Tree 
    [. parent 
        [.{nice child0}
                [.{grandchild0-0 } ]
            [.{grandchild0-1 } ]
            [.{grandchild0-2 } ]
            [.{grandchild0-3 } ]
        ]
        [[[.child1
            [.{grandchild1-0 } ]
            [.{grandchild1-1 } ]
            [.{grandchild1-2 } ]
        ]]]
        [.child2 ]
        [.child3 ]
    ]
\end{tikzpicture}
\end{document}

output of code

share|improve this answer
    
Thank you, but there is another thing I'd like to modify on it. Namely to reduce its height. Using your figure nodenames... the gap between "nice child0" and "child2" is as wide as child1's grandchild. But I'd like to reduce it. This is why I mainly wanted the modification you gave me. –  Greg May 8 '12 at 19:25
    
@greg tikz-qtree is designed to automatically calculate the node spacing (which is why it's so useful), but this comes at the expense of not having individual control of specific nodes, I think. –  Alan Munn May 8 '12 at 19:44

I managed to find a solution to my problem without qtree based on this one: How to modify the distance between branches when drawing trees using TiKZ?

The code:

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{trees}%szögletességhöz kell
\begin{document}

\begin{tikzpicture}[grow'=right,level distance=90pt,sibling distance=30pt]

\tikzset{edge from parent/.style= 
{thick, draw, edge from parent fork right}
}

    \node [draw] (z){parent}
        child { 
            node[draw] (a) {child0}
            child { 
                node[draw] (c) {grandchild0-0} 
            }
            child { 
                node[draw] (d) {grandchild0-1} 
            }   
            child { 
                node[draw] (e) {grandchild0-2} 
            }   
            child { 
                node[draw] (f) {grandchild0-3} 
            }   
        }
        child {
            node[draw] (b) {child1}
        }
        child {
            node[draw] (b) {child2}
        }
        child {
            node[draw] (b) {child3}
            child { 
                node[draw] (c) {grandchild3-0} 
            }
            child { 
                node[draw] (c) {grandchild3-1} 
            }
        }
        ;

    \path (z) -- (a);
    \path (z) -- (b);
    \path (a) -- (c);
    \end{tikzpicture}

\end{document}

output

share|improve this answer
1  
I realise it is your question, but I don't see how this answers it! –  cfr Apr 5 at 13:22

Here's a solution using forest which is an extremely flexible and powerful package for drawing trees. It offers the automatisation of qtree plus the ability to customise the format and placement of individual nodes, branches and edges, when required.

It does an especially good job of automatically packing the nodes to make compact trees. [But you could further compress the tree with manual adjustments if required.]

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
  for tree={
    grow'=0,
    parent anchor=east,
    child anchor=west,
    anchor=west,
    thick,
    draw,
    edge path={
      \noexpand\path [draw, thick, \forestoption{edge}] (!u.parent anchor) -- +(5pt,0) |- (.child anchor)\forestoption{edge label};
    },
    if level=1{
      tier=children,
      if n=2{
        for children={
          tier=grandchildren 2,
          delay={
            edge path={
              \noexpand\path [draw, thick, \forestoption{edge}] (!u.parent anchor) -| ([xshift=-5pt].child anchor) -- (.child anchor)\forestoption{edge label};
            },
          }
        },
      }{
        for children={tier=grandchildren 1}
      },
    }{},
  }
  [root
    [child 1
      [grandchild 1
        [,phantom, tier=grandchildren 2]
      ]
      [grandchild 2]
      [grandchild 3]
    ]
    [child 2
      [grandchild 4]
      [grandchild 5]
      [grandchild 6]
    ]
    [child 3
      [grandchild 7]
      [grandchild 8]
    ]
  ]
\end{forest}
\end{document}

special second child

Note that if you just want the grandchildren packed as shown in your answer, the solution is significantly simpler:

\begin{forest}
  for tree={
    grow'=0,
    parent anchor=east,
    child anchor=west,
    anchor=west,
    thick,
    draw,
    edge path={
      \noexpand\path [draw, thick, \forestoption{edge}] (!u.parent anchor) -- +(5pt,0) |- (.child anchor)\forestoption{edge label};
    },
  }
  [root
    [child 1
      [grandchild 1]
      [grandchild 2]
      [grandchild 3]
      [grandchild 4]
    ]
    [child 2]
    [child 3]
    [child 4
      [grandchild 7]
      [grandchild 8]
    ]
  ]
\end{forest}

simple packed nodes

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.