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.

enter image description here

01, 001 and 0001 are not actually "childs". How do I add K=1,2,3 and K=4 to the left hand column? And I tried really hard to adjust the distance. But this is the best I can do.

Thanks.

\documentclass[landscape]{article}

\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}

\pagestyle{empty}

\begin{tikzpicture}

\node{1}
    child{
        node{10}
        child{
            node{100}
            child{
                node{1000}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{1001}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
        child{
            node{101}
            child{
                node{1010}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{1011}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
    }
    child{
        node{11}
        child{
            node{110}
            child{
                node{1100}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{1101}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
        child{
            node{111}
            child{
                node{1110}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{1111}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
    }
    child{
        node{01} edge from parent[draw=none]
        child{
            node{010}
            child{
                node{0100}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{0101}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
        child{
            node{011}
            child{
                node{0110}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{0111}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
        child{
            node{001} edge from parent[draw=none]
            child{
                node{0010}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{0011}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{0001} edge from parent[draw=none]
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
    };
\end{tikzpicture}



\end{document}
share|improve this question
    
Duplicate of Tikz tree drawing with comments to each level –  Alan Munn Aug 30 '13 at 2:15
2  
@AlanMunn I agree that the first part (the one regarding the labels) is a duplicate of the question you linked to; the other part (a way to draw the four trees), is not a duplicate (at least not of the linked question). –  Gonzalo Medina Aug 30 '13 at 3:03
    
@AlanMunn I'm glad this is still here, at least, as these questions are now importantly different from my admittedly idiosyncratic point of view! (One wants justtrees, I think. The other wants prooftrees. Or so I claim.) –  cfr Jun 26 at 23:39

2 Answers 2

up vote 6 down vote accepted

For the first part of your question (placing the labels to the left) the idea is to place names to the nodes on the left-most branch and then use these names to place the labels. For the second part, I'd suggest you to draw each tree separately using scopes:

\documentclass[landscape]{article}
\usepackage{tikz}
\usetikzlibrary{trees,positioning}

\begin{document}

\pagestyle{empty}

\begin{tikzpicture}[xscale=0.8,
level 1/.style={sibling distance=12em},
level 2/.style={sibling distance=6em},
level 3/.style={sibling distance=3em},
level 4/.style={sibling distance=2em},
]
\node (k1) {1}
    child{
        node (k2) {10}
        child{
            node (k3) {100}
            child{
                node (k4) {1000}
                child{node {$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{1001}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
        child{
            node{101}
            child{
                node{1010}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{1011}
                child{node {$\vdots$}}
                child{node{$\vdots$}}
            }
        }
    }
    child{
        node (11) {11}
        child{
            node{110}
            child{
                node{1100}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{1101}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
        child{
            node{111}
            child{
                node{1110}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{1111}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
};
\node[left=of k4] (aux) {$k=4$};
\foreach \val \i in {1,2,3} 
  \node at (aux|-k\i) {$k=\i$};
\begin{scope}[
level 1/.style={sibling distance=8em},
level 2/.style={sibling distance=4em},
level 3/.style={sibling distance=2em},
]
\node[right=3.5cm of 11]{01}
        child{
            node  {010}
            child{
                node  {0100}
                child{node {$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{0101}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
        }
        child{
            node (011) {011}
            child{
                node{0110}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{0111}
                child{node {$\vdots$}}
                child{node{$\vdots$}}
            }
        };
\end{scope}    
\begin{scope}[
level 1/.style={sibling distance=4em},
level 2/.style={sibling distance=2em},
]
\node[right=1.5cm of 011] {001}
            child{
                node (0010) {0010}
                child{node {$\vdots$}}
                child{node{$\vdots$}}
            }
            child{
                node{0011}
                child{node{$\vdots$}}
                child{node{$\vdots$}}
            };
\end{scope}    
\begin{scope}[
level 1/.style={sibling distance=1.5em},
]
\node[right=1.2cm of 0010] {0001}
                child{node {$\vdots$}}
                child{node{$\vdots$}
            };
\end{scope}    
\end{tikzpicture}

\end{document}

enter image description here

Perhaps you could be interested in the powerful forest package.

share|improve this answer

This answer uses version 0.07 of an experimental package, prooftrees. This is based on forest and all of the magic is being done by that package. The key single branches is provided by prooftrees and is needed to get the spacing right in this case. \linecountformat is also provided by the package (and was added for the purpose of answering this question - I'm trying to figure out what kinds of things might be actually useful to people other than me). It is renewed here to change the format of the numbers on the left.

The alignments of k=1, k=2 etc. are managed automatically, as are the values 1, 2 and so on. A couple of phantom nodes are used to get the placement of the trees to the right of the initial one correct, and forest's power is used to automatically specify most nodes' content. Only the content for the tree root nodes and the structure of the trees needs to be manually specified.

If you wish to try this at home, note that this is all very dodgy. Let me know and I will post an updated copy of the package for you. (The one on this site already is version 0.06 which doesn't let you change the format of the line numbers.)

Caveat emptor...

\documentclass[tikz, border=5pt]{standalone}
\usepackage{prooftrees}% v0.07

\begin{document}
\begin{prooftree}
  {
    TeX={\renewcommand*\linecountformat[1]{k=#1}},
    for tree={
      before typesetting nodes={
        if content={}{
          if n=1{
            content/.wrap pgfmath arg={#1{}0}{content("!u")},
          }{
            if n'=1{
              content/.wrap pgfmath arg={#1{}1}{content("!u")},
            }{}
          }
        }{}
      },
      tier/.wrap pgfmath arg={tier #1}{level()}
    },
    single branches
  }
  [1
    [
      [
        []
        []
      ]
      [
        []
        []
      ]
    ]
    [
      [
        []
        []
      ]
      [
        []
        []
      ]
    ]
  ]
  [, phantom
    [01
      [
        []
        []
      ]
      [
        []
        []
      ]
    ]
  ]
  [, phantom
    [, phantom
      [001
        []
        []
      ]
    ]
  ]
\end{prooftree}
\end{document}

automated tree drawing with <code>prooftrees</code>

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.