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

1 Answer 1

up vote 5 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

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.