5

I have this tree:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree}

\begin{document}
\begin{tikzpicture}
\tikzstyle{level 1}=[sibling distance=50pt]
\tikzstyle{level 2}=[sibling distance=30pt]
\tikzstyle{level 3}=[sibling distance=25pt]
\tikzstyle{level 4}=[sibling distance=15pt]
\begin{scope}[xshift=3cm]
\Tree [.\node(a1){$\ \Delta^1$};
\edge node[auto=right,scale=0.7]{$q_1$};
[.{ $q_1\cdot\Delta^2$}
    \edge node[auto=right,scale=0.7]{$q_5$};
    {}
    \edge node[auto=left,scale=0.7]{$q_6$};
    [.{$q_6\cdot\Delta^7$} % TODO add Cartesian product here
        \edge node[auto=right,scale=0.7]{$q_{13}$};
        {}
        \edge node[auto=left,scale=0.7]{$q_{14}$}; 
        {}
        \edge node[auto=left,scale=0.7]{$q_{15}$}; 
        {}
        ]
    ]
%
\edge node[auto=left,scale=0.7]{$q_2$};
[. {$q_2\cdot\Delta^3$}
\edge node[auto=right,scale=0.7]{$q_7$};
        {} 
\edge node[auto=left,scale=0.7]{$q_8$};
        {} 
]
]
\end{scope}
\begin{scope}[xshift=9cm]
\Tree [.\node(a2){$\ \Delta^2$};
\edge node[auto=right,scale=0.7]{$q_3$};
[. {$q_3\cdot\Delta^5$}
\edge node[auto=right,scale=0.7]{$q_9$};
        {} 
\edge node[auto=left,scale=0.7]{$q_{10}$};
        {} 
]
\edge node[auto=left,scale=0.7]{$q_{4}$};
[. {$q_4\cdot\Delta^6$}
\edge node[auto=right,scale=0.7]{$q_{11}$};
        {} 
\edge node[auto=left,scale=0.7]{$q_{12}$};
        {} 
]
]
\end{scope}
\path (a1) -- node {$\times$} (a2);
\end{tikzpicture}
\end{document}

But, as can hopefully be seen in this pic, the edge from $q_1\cdot\Delta^2$ is too long compared to other edges at the same level. Any ideas on how to fix this? Thanks!

enter image description here

  • 1
    You can add \vphantom{$q_6\cdot\Delta^7$} to the node after that edge, and it will be the same length, then. – Adam Liter Feb 6 '15 at 16:00
5

Gonzalo's answer is a nice way if you don't mind switching to the forest package. However, if you want to keep the code you have already written and continue using tikz-qtree, you can add \vphantom{$q_6\cdot\Delta^7$} to the node after that edge. This will add invisible vertical space in that node that is the same height as the vertical space in its sister node.

Result

enter image description here

Code

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree}

\begin{document}
\begin{tikzpicture}
\tikzstyle{level 1}=[sibling distance=50pt]
\tikzstyle{level 2}=[sibling distance=30pt]
\tikzstyle{level 3}=[sibling distance=25pt]
\tikzstyle{level 4}=[sibling distance=15pt]
\begin{scope}[xshift=3cm]
\Tree [.\node(a1){$\ \Delta^1$};
\edge node[auto=right,scale=0.7]{$q_1$};
[.{ $q_1\cdot\Delta^2$}
    \edge node[auto=right,scale=0.7]{$q_5$};
    {\vphantom{$q_6\cdot\Delta^7$}}
    \edge node[auto=left,scale=0.7]{$q_6$};
    [.{$q_6\cdot\Delta^7$} % TODO add Cartesian product here
        \edge node[auto=right,scale=0.7]{$q_{13}$};
        {}
        \edge node[auto=left,scale=0.7]{$q_{14}$}; 
        {}
        \edge node[auto=left,scale=0.7]{$q_{15}$}; 
        {}
        ]
    ]
%
\edge node[auto=left,scale=0.7]{$q_2$};
[. {$q_2\cdot\Delta^3$}
\edge node[auto=right,scale=0.7]{$q_7$};
        {} 
\edge node[auto=left,scale=0.7]{$q_8$};
        {} 
]
]
\end{scope}
\begin{scope}[xshift=9cm]
\Tree [.\node(a2){$\ \Delta^2$};
\edge node[auto=right,scale=0.7]{$q_3$};
[. {$q_3\cdot\Delta^5$}
\edge node[auto=right,scale=0.7]{$q_9$};
        {} 
\edge node[auto=left,scale=0.7]{$q_{10}$};
        {} 
]
\edge node[auto=left,scale=0.7]{$q_{4}$};
[. {$q_4\cdot\Delta^6$}
\edge node[auto=right,scale=0.7]{$q_{11}$};
        {} 
\edge node[auto=left,scale=0.7]{$q_{12}$};
        {} 
]
]
\end{scope}
\path (a1) -- node {$\times$} (a2);
\end{tikzpicture}
\end{document}
7

An nice answer was provided by Adam Liter using tikz-qtree, but here I want to show an alternative approach using the powerful forest package; notice, in particular, the shorter, cleaner code; the direct issue in the question was addressed here in a different way using the text height key for the nodes so they will all have the same height independently of their content:

\documentclass{standalone}
\usepackage{forest}

\begin{document}

\forestset{
leftedge/.style={
  edge label={node[inner sep=1pt,midway,auto,swap,font=\scriptsize]{$#1$}}
  },
rightedge/.style={
  edge label={node[inner sep=1pt,midway,auto,font=\scriptsize]{$#1$}}
  }
}
\begin{forest}
for tree={
  parent anchor=south,
  child anchor=north,
  math content,
  text height=2ex,
  l sep=25pt,
  s sep=20pt,
  where level={3}{s sep=30pt}{}
}
[,phantom,
  [\ \Delta^1
    [q_{1}\cdot\Delta^{2},leftedge={q_{1}}
      [,leftedge={q_{5}}
      ]
      [q_{6}\cdot\Delta^{7},rightedge={q_{6}}
        [,leftedge={q_{13}}]
        [,rightedge={q_{14}}]
        [,rightedge={q_{15}}]
      ]
    ]
    [q_{2}\cdot\Delta^{3},rightedge={q_{2}}
      [,leftedge={q_{7}}
      ]
      [,rightedge={q_{8}}
      ]
    ]
  ]
  [\ \Delta^2
    [q_{3}\cdot\Delta^{5},leftedge={q_{3}}
      [,leftedge={q_{9}}
      ]
      [,rightedge={q_{10}}
      ]
    ]
    [q_{4}\cdot\Delta^{6},rightedge={q_{4}}
      [,leftedge={q_{11}}
      ]
      [,rightedge={q_{12}}
      ]
    ]
  ]
]
\end{forest}

\end{document}

enter image description here

  • Thanks for your helpful comment! I upvoted, and I might check out forest in the future, but for now, my paper deadline makes me prefer to stick with what I have :) – bassen Feb 7 '15 at 18:26

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.