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'm new to TikZ, and I'm having a terrible time figuring out how to create an image similar to this.

enter image description here

So far I am able to create all the rectangles, but there are two things I cannot figure out how to do:

  1. I'd like to replace the B symbols region with an ellipses in the center to show continuation, and
  2. Is there an elegant way to specify positioning for the labels, beyond just coordinates, so that moving around the rectangle regions moves the associated labels?
share|improve this question
2  
You should show the code you have produced until now to provide a starting point to who can help you –  Spike Oct 9 '12 at 14:49
2  
You could have a look at the bytefield package. –  Tom Bombadil Oct 9 '12 at 21:55
    
@TomBombadil : You may find the bytefield package isn't quite up to this level of elegance... –  Brent.Longborough Oct 10 '12 at 15:39

1 Answer 1

up vote 9 down vote accepted

Here's one possibility (I wasn't sure of the desired layout for the central region):

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

% the styles for short and long nodes
\tikzset{
short/.style={draw,rectangle,text height=3pt,text depth=13pt,
  text width=7pt,align=center,fill=gray!30},
long/.style={short,text width=1.5cm}
}

\begin{document}

% the short nodes \shnode{<label>}{<right of>}{<text>}
\def\shnode#1#2#3{%
  \node[short,right=of #1] (#2) {\rotatebox{270}{#3}}}

% the long nodes \lnode{<label>}{<right of>}
\def\lnode#1#2{%
  \node[long,right=of #1] (#2) {}}

\noindent\begin{tikzpicture}[node distance=-\pgflinewidth]

\node[short,fill=black] (a) {};
\shnode{a}{b}{src};
\shnode{b}{c}{dst};
\shnode{c}{d}{len};
\lnode{d}{e};
\lnode{e}{f};
\node[long,draw=none,fill=none,right=of f,text height=0pt,text depth=0pt,text width=1cm] (g) {$\ldots$};
\node[long,right=of g,label=center:$b$ bits] (h) {};
\lnode{h}{i};
\shnode{i}{j}{len};
\shnode{j}{k}{dst};
\shnode{k}{l}{src};
\node[short,fill=black,right=of l] (m) {};

\node[above right=1cm of a] (ppre) {Packet preamble};
\node[above left=1cm of m] (ppos) {Packet postamble};

\draw[decorate,decoration={brace,raise=2pt}] (b.north west) -- node[above=4pt] {Header} (d.north east);
\draw[decorate,decoration={brace,raise=2pt}] (j.north west) -- node[above=4pt] {Trailer} (l.north east);
\draw[decorate,decoration={brace,raise=2pt}] (h.north west) -- node[above=4pt] {Codeword} (h.north east);
\draw (ppre.west) -- +(-20pt,0pt) -- (a.north);
\draw (ppos.east) -- +(20pt,0pt) -- (m.north);
\draw (a.south east) -- +(0,-1.2cm);
\draw (m.south west) -- +(0,-1.2cm);
\draw[<->] ( $ (a.south east) +(0,-0.6cm) $ ) -- node[fill=white] {$S/B$ Codewords} ( $ (m.south west) +(0,-0.6cm) $ );
\draw[,dotted] (f.north east) -- (h.north west);
\draw[dotted] (f.south east) -- (h.south west);

\end{tikzpicture}

\end{document}

enter image description here

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.