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.

I would like to create TikZ something like:

-------------------------------  ...   ----------------
| 0000 | 0001 | 0010 | 0100 |           | 0111 | 1111 |
------------------------------  ...   -----------------
\     / \                  /                    \     /
 \M_0/   \------ M_1------/                      \M_d/

where I could give the first box one color, the 3 box after words different color and the last one a 3rd color.

I tried to create \underbrace for the M_0, M_1 and M_d

Does someone know where I could find short example for something like this?

EDIT

Thank you for the nice solutions. In my example above it was hard to see and also to create an example for it, so below is an example how i would like to have the connecting box. I hope it is also possible a relative easy way.

enter image description here

share|improve this question
2  
You could have a look at this question: tex.stackexchange.com/questions/31336/…. It should be straightforward to add some color in TikZ. Just use the color=colorname option. –  Roelof Spijker Dec 12 '11 at 16:30
    
If the above link solves your question, we should close this one. If it doesn't, please make clear how it doesn't. –  Seamus Dec 12 '11 at 16:51
    
Answers in the link are (too) complex for this kind of problem but it's a personal point of view. –  Alain Matthes Dec 12 '11 at 17:10
    
@Seamus, this solution is in the direction of what i am searching for, but not exactly. Please see the edit part. –  Eagle Dec 12 '11 at 17:56
    
@Eagle: I've updated my answer to include dashed lines - slightly crude, but since I had something sans-tikz originally, I stuck to it. :) –  Werner Dec 12 '11 at 18:40
add comment

4 Answers

up vote 10 down vote accepted

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

share|improve this answer
add comment

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.

share|improve this answer
3  
hehe... I was just about to post a similar TikZ-free solution. –  Gonzalo Medina Dec 12 '11 at 17:29
1  
a bit shorter: \newcommand\cbox[2]{\fcolorbox{black}{#1}{\texttt{#2\strut}}\kern-\fboxrule} –  Herbert Dec 12 '11 at 17:33
    
@Herbert: Thanks - that's great! –  Werner Dec 12 '11 at 18:39
add comment
\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

share|improve this answer
add comment

You can create the wiggly lines manually using Bezier curves, enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \newcommand\WigglyStrength{2/3}
    % Left box
    \draw
        (0,0)
        -- ++(2,0)
        .. controls +(\WigglyStrength,1/3) and +(-\WigglyStrength,-1/3) .. ++(0,1)
        -- ++(-2,0)
        ;
    % Right box
    \draw
        (6,0)
        -- ++(-2,0)
        .. controls +(\WigglyStrength,1/3) and +(-\WigglyStrength,-1/3) .. ++(0,1)
        -- ++(2,0)
        ;
    % Dashed lines
    \draw [dashed]
        (0,0) ++(2,0) -- ++(2,0)
        (0,1) ++(2,0) -- ++(2,0)
        ;
\end{tikzpicture}
\end{document}
share|improve this answer
add comment

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.