6

I'm trying to draw a tree that has internal nodes with only one child, but which must be oriented.

    /
    \
    /\
      \
      /\

Instead of the typical qtree where said children just "hang":

    |
    |
   / \
      |
      |
     / \

I think (but I do not know how) it might be possible to have invisible leaves to force the direction, but perhaps (hopefully) there is a better solution? This can be in either qtree or tikz-qtree...

EDIT: follow-up question that would be useful, how can make each branch (in a straight line) distinct when the nodes are not labeled -- i.e., when the tree is has several connections in a row, like in the second example, how can I make them slightly spaced from one another so they do not form a straight undistinguishable line?

EDIT 2: thanks your response, I now have these two trees:

  \documentclass[tikz]{standalone}
  \usepackage{tikz-qtree}
  \begin{document}
  \begin{tikzpicture}\footnotesize
    \Tree [ \edge node[midway,left] {000};
          [ \edge[draw=none]; {} \edge node[midway,right] {111};
            [
            \edge node[midway,left] {0}; $U_2$
            \edge node[midway,right] {11};
            [ \edge[draw=none]; {} \edge node[midway,right] {11};
            [ \edge node[midway,left] {0}; $U_1$
                \edge node[midway,right] {1}; $U_3$ ] ] ] ]
          \edge[draw=none]; {}  ]
  \end{tikzpicture}
  \begin{tikzpicture}\footnotesize
    \Tree [ \edge node[midway,right] {$U_1=U_2$, $U_1=U_3$};
          [.. \edge node[midway,right] {$U_1=U_2$, $U_1=U_3$};
          [ \edge node[midway,left] {$0$}; $U_2$ 
              \edge node[midway,right] {$U_1\not=U_2$, $U_1 = U_3$}; [
                  \edge node[midway, right] {$U_1 = U_3$}; 
                  [ \edge node[midway, left] {$0$}; $U_1$
                      \edge node[midway, right] {$U_1\not=U_3$}; $U_3$ ] ] ] ] ]
  \end{tikzpicture}
  \end{document}

Any idea on how to make them look better?

0

2 Answers 2

5

Use an empty node {} and place an \edge[draw=none]; in front of it.

Code

\documentclass[tikz]{standalone}
\usepackage{tikz-qtree}
\tikzset{
    n/.style={draw=none},
    every node/.append style={inner ysep=+0pt,outer ysep=+0pt,minimum size=+0pt}
}
\begin{document}
\Tree
    [.{}
        [.{} 
            \edge[n];[.{} ]
            [.{}
                {} 
                [.{}
                    \edge[n];[.{} ]
                    [.{} 
                        {} 
                        {} 
                    ]
                ]
            ]
        ]
        \edge[n];{} 
    ]
\end{document}

Output (without and with every node style activated)

enter image description here enter image description here

2
  • 1
    Thank you. But such a tree looks a bit disjointed?
    – Jérémie
    Commented Apr 10, 2013 at 3:59
  • 1
    @Jérémie Well, if you really do not write anything in the nodes, then yes, they won’t connect, but this can be forced with the given every node style. (See updated answer.) Commented Apr 10, 2013 at 4:10
2

You can also use xshift (and yshift) to fine-tune where you want your nodes to be.

\documentclass[tikz]{standalone}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}\footnotesize
  \Tree [.{a}
      \edge node[midway,left] {1};
      [.\node[xshift=0.5cm,inner sep=0pt,minimum size=0pt] {}; \edge node[midway,left] {2}; {c} ]
  ]
\end{tikzpicture}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .