The manual of the bytefield package explains how to color a normal bitfield with a colored \rule. I'm also using the \skippedwords command in my figures. I would like to also color that fields. However, it seems that there is no option in the bytefield package for a general color changing. Does somebody has an idea how to accomplish that, a workaround or a package suggestion? I know that I could draw everything with tikz but I would like to avoid that.

  • 1
    Providing a working example would be beneficial for those seeking to offer help. Welcome to the site. – Steven B. Segletes Feb 6 '14 at 20:19

In the following, I defined a command \cskippedwords allowing you to apply a background color using the mandatory argument. The syntax is


where the optional argument <length> has the same meaning that for the standard \skippedwords, and color will be applied with a 0.2 opacity.

The code:


  \setlength{\units@wide}{\bf@bitwidth * \bits@wide}%
  \setlength{\units@high}{1pt * \ratio{\units@wide}{6.0pt}}%
  \setlength{\units@tall}{#1 + \units@high}%
  \draw[fill=#2,fill opacity=0.2] 
    (0,-\bf@bitheight) -- (0,0) -- (0,\units@high) -- (\units@wide,0) -- +(0,-\bf@bitheight) -- cycle;
  \draw[fill=#2,fill opacity=0.2]
    (0,\units@high+#1+\bf@bitheight) -- ++(\units@wide,0) -- ++(0,-\bf@bitheight-\units@high) -- (0,\units@high+#1) -- cycle;
    \inc@bytefield@height{\unitlength * \real{\num@tall}}%

\wordbox{1}{Some data} \\
\wordbox[lrt]{1}{Lots of data} \\
\cskippedwords{blue!20} \\
\wordbox[lrb]{1}{} \\
\wordbox{2}{More data}


\bitheader{0,7,8,15,16,23,24,31} \\
\begin{rightwordgroup}{\parbox{6em}{\raggedright These words were taken
verbatim from the TCP header definition (RFC~793).}}
\bitbox{4}{Data offset} & \bitbox{6}{Reserved} &
\bitbox{1}{\tiny U\\R\\G} & \bitbox{1}{\tiny A\\C\\K} &
\bitbox{1}{\tiny P\\S\\H} & \bitbox{1}{\tiny R\\S\\T} &
\bitbox{1}{\tiny S\\Y\\N} & \bitbox{1}{\tiny F\\I\\N} &
\bitbox{16}{Window} \\
\bitbox{16}{Checksum} & \bitbox{16}{Urgent pointer}
\end{rightwordgroup} \\
\wordbox[lrt]{1}{Data octets} \\
%\skippedwords \\
\cskippedwords{green} \\
\wordbox[lrb]{1}{} \\
\begin{leftwordgroup}{\parbox{6em}{\raggedright Note that we can display,
for example, a misaligned 64-bit value with clever use of the
optional argument to \texttt{\string\wordbox} and
\bitbox{8}{Source} & \bitbox{8}{Destination} &
\bitbox[lrt]{16}{} \\
\wordbox[lr]{1}{Timestamp} \\
\begin{rightwordgroup}{\parbox{6em}{\raggedright Why two Length fields?
No particular reason.}}
\bitbox[lrb]{16}{} & \bitbox{16}{Length}
\end{leftwordgroup} \\
\bitbox{6}{Key} & \bitbox{6}{Value} & \bitbox{4}{Unused} &


enter image description here

  • @Flasher You're welcome. I updated my answer fixing a little problem with one of the lengths I used; the improved code might be of interest for you. – Gonzalo Medina Feb 7 '14 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.