Use Tikz to draw this beautiful symmetric tree

This is a modification of your original code. I think there are better ways of achieving this, using less explicit coordinates, but this is at least some inspiration.

enter image description here

\documentclass[12pt,fleqn]{article}    
\usepackage[portuguese,brazil]{babel}    
\usepackage[latin1]{inputenc}    
\usepackage{tikz}    
\usepackage{xcolor}    
\begin{document}    
\begin{tikzpicture}[scale=.7,every node/.append style={font=\bfseries\sffamily}]    
\fill[blue!10] (-1.5,-7) rectangle (1,7); 
\fill[blue!10] (2,-7) rectangle (3,-0.5); 
\fill[blue!10] (2,0.5) rectangle (3,7); 

\fill[red!10] (4,-7) rectangle (5,-0.5); 
\fill[red!10] (4,0.5) rectangle (5,7); 

\fill[yellow!30] (6,-7) rectangle (8,-0.5); 
\fill[yellow!30] (6,0.5) rectangle (8,7);  

\node (start) at (-0.2,0) {START};    
\node (T) at (2.5,-3.75) {T};    
\node (H) at (2.5,3.75) {H};    

\foreach [count=\i] \y in {1.25,2.25,...,6.25}
 {
  \node (t\i) at (4.5,-\y) {\i};
  \node (h\i) at (4.5,\y) {\i};
  \node (tp\i) at (7,-\y) {(T,\i)};
  \node (hp\i) at (7,\y) {(H,\i)};

  \draw (H.east) -- (h\i);
  \draw (T.east) -- (t\i);
 }

\draw (start.east) -- (H);
\draw (start.east) -- (T);

\end{tikzpicture}    
\end{document}

Here's a version of the diagram constructed using the power tree-drawing package, forest, in combination with the TikZ libraries fit and backgrounds. Forest's relative node names are used to locate the coordinates to include in the shaded boxes, fit is used to ensure they are correctly included and backgrounds is used to add the shading behind the tree after the tree is constructed.

While Forest takes a little getting used to, it is worth the trouble, especially since the full power of TikZ remains available in addition to Forest's own facilities.

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\usetikzlibrary{fit,backgrounds}
\begin{document}
\begin{forest}
  before packing={
    for tree={
      grow'=0,
      parent anchor=children,
      child anchor=parent,
      l sep'+=20pt,
    },
    where={level()>0}{
      s sep'-=10pt,
    }{}
  },
  where level=0{
    font=\sffamily\bfseries,
    tikz+={
      \begin{scope}[on background layer, every node/.append style={fill opacity=.25, inner ysep=0pt}]
        \node [fill=blue!50!cyan, fit=() ( |- !F.north) ( |- !L.south)] {};
      \end{scope}
    },
    for children={
      tikz+={
        \begin{scope}[on background layer, every node/.append style={fill opacity=.25, inner ysep=0pt}]
          \node [fill=blue!25!cyan, fit=() ( |- !F.north) ( |- !L.south)] {};
          \node [fill=blue!75!cyan, fit=(!1) (!6) (!1 |- !F.north) (!6 |- !L.south)] {};
          \node [fill=orange!50!yellow, fit=(!11) (!61) (!11 |- !F.north) (!61 |- !L.south)] {};
        \end{scope}
      },
    }
  }{},
  where n children=0{
    before typesetting nodes={
      font=\sffamily\bfseries,
      repeat=6{
        append={
          [, content/.option=n, font=\sffamily\bfseries,
            [, content/.wrap 2 pgfmath args={(##1,##2)}{content("!uu")}{n("!u")}, no edge, font=\sffamily\bfseries,
            ]
          ]
        }
      }
    }
  }{}
  [START
    [H
    ]
    [T
    ]
  ]
\end{forest}
\end{document}

Forest solution

Tags:

Tikz Pgf