Create an array in TikZ with \underbrace in different colors

This solution builds on Altermundus answer; I only used the shapes library to add two "tapes" to get the desired aspect for the interrupted band:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,shapes}

\begin{document}
\begin{tikzpicture}
 \foreach \c/\i [count=\n] in  
        {blue!20/0001,red!20/0001,red!20/0010,red!20/0100} 
           \node[draw,fill=\c,minimum height=1cm,minimum width = 2cm,xshift=\n*2cm,font=\ttfamily](N\n){\i} ;

  \draw [decoration={brace,mirror,raise=5pt},decorate] (N1.south west) --  node[below=10pt]{$M_0$}(N1.south east); 
  \draw [decoration={brace,mirror,raise=5pt},decorate] (N1.south east) --  node[below=10pt]{$M_1$}(N4.south east);

  \node [tape, draw,minimum size=1cm,tape bend top=none,
tape bend height=0.4cm,rotate=90] at (9.3,0) (t) {};
  \node [tape, draw,minimum size=1cm,tape bend top=none,
tape bend height=0.4cm,rotate=270] at (11.3,0) (t) {};

\node at (10.3,0.5) {\dots};
\node at (10.3,-0.5) {\dots};

\foreach \c/\i [count=\m] in  
        {olive!20/0111,green!20/1111} 
           \node[draw,fill=\c,minimum height=1cm,minimum width = 2cm,xshift=10.6cm+\m*2cm](N\m){\i} ;
  \draw [decoration={brace,mirror,raise=5pt},decorate] (N2.south west) --  node[below=10pt]{$M_d$}(N2.south east); 

 \end{tikzpicture}

\end{document}

enter image description here


\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
 \foreach \c/\i [count=\n] in  
        {blue!20/0001,red!20/0001,red!20/0010,red!20/0100,white/\dots,yellow!20/0100} 
           \node[draw,fill=\c,minimum height=1cm,minimum width = 2cm,xshift=\n*2cm](N\n){\i} ;

 \draw [decoration={brace,mirror,raise=5pt},decorate] (N1.south west) --  node[below=10pt]{$M_0$}(N1.south east); 
 \draw [decoration={brace,mirror,raise=5pt},decorate] (N1.south east) --  node[below=10pt]{$M_1$}(N4.south east);

\end{tikzpicture}
\end{document}

enter image description here

Update : Gonzalo was faster than me ! My code below is not complete I stop it when I saw the good answer of Gonzalo. I put my idea because I find a great difficulty. In my idea the connecting boxes contained numbers. here the result :

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,shapes}
\begin{document}
\begin{tikzpicture}
   \node[tape, draw,fill=red!20, tape bend top=none,rotate=90,minimum width=1cm,minimum height=2cm] at (7.92, 0) {};  
  \node[tape, draw,fill=yellow!20, tape bend bottom=none,rotate=90,minimum width=1cm,minimum height=2cm] at (12, 0) {};   
 \foreach \c/\i/\b [count=\n] in  
        {blue!20/0001/1,red!20/0001/1,red!20/0010/1,/0100/0,//0,/0100/0} 
{\ifnum \b=1
  \node[draw,fill=\c,minimum height=1cm,minimum width = 2cm,xshift=\n*2cm](N\n){\i} ;
  \else  
    \node[minimum height=1cm,minimum width = 2cm,xshift=\n*2cm](N\n){\i} ;  
  \fi }

 \draw [decoration={brace,mirror,raise=5pt},decorate] (N1.south west) --  node[below=10pt]{$M_0$}(N1.south east); 
  \draw [decoration={brace,mirror,raise=5pt},decorate] (N1.south east) --  node[below=10pt]{$M_1$}(N4.south east); 

\end{tikzpicture}
\end{document} 

The difficulty is real ! because I can't rotate nodes with numbers inside.

enter image description here


Another option without using tikz/pgf:

enter image description here

\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\newsavebox{\tempbox}
\newcommand{\cbox}[2]{%
  \fcolorbox{black}{#1}{\texttt{#2\strut}}\kern-\fboxrule}% Coloured box
\begin{document}
\[
  \savebox{\tempbox}{\cbox{white}{~~~~~~}}
  \underbrace{\cbox{red!30}{0000}}_{M_0}\!
  \underbrace{\cbox{green!20}{0001}
    \cbox{green!20}{0010}
    \cbox{green!20}{0100}}_{M_1}\!
  \rlap{\usebox{\tempbox}}%
  \makebox[\wd\tempbox][c]{%
    \fcolorbox{white}{white}{$\!\strut\cdot\!$}~%
    \fcolorbox{white}{white}{$\!\strut\cdot\!$}~%
    \fcolorbox{white}{white}{$\!\strut\cdot\!$}}\!
  \cbox{white}{0111}\!
  \underbrace{\cbox{blue!40}{1111}}_{M_d}
\]
\end{document}​

The macro \cbox{<color>}{<stuff>} typesets <stuff> in the appropriate (framed) \fcolorbox with colour <color>. Modifying the frame colour to white and overlaying it on the enlarged rectangle multiple times (slightly spaced) provides the faux dashed line style to "break" the sequence.

Tags:

Tikz Pgf