I wonder why it is not easily possible to put a bytefield enviroment into a tabular. This MWE
\documentclass[border=2mm]{standalone}
\usepackage{bytefield}
\begin{document}
\begin{tabular}{c}
\begin{bytefield}{2}
\bitheader{0-1} \\ \bitbox{1}{0} \bitbox{1}{2}
\end{bytefield}
\end{tabular}
\end{document}
produces this pdflatex error:
! Extra }, or forgotten \endgroup.
<template> \unskip \hfil }
\hskip \tabcolsep \endtemplate
l.5 \begin{bytefield}{2}
Because of the valid answer to this question, I fear that it's again some key codes which are mangled by bytefield. But I lack the ability to find the solution.
Edit (addendum):
While enclosing the bytefield in braces helps with the simple example, I noticed that trouble comes with more complicated use. Since the alignmend of the bytefield is a bit weird, I feel forced into using \raisebox
so that the bytefield numbers no longer overlap with the previous line.
Freakingly, this works only with the first line. Consider this advanced example:
\documentclass[border=2mm]{standalone}
\usepackage{bytefield}
\begin{document}
\begin{tabular}{l}\hline
\raisebox{-1ex}[5ex][1.5ex]{
{\begin{bytefield}[endianness=big,bitwidth=5em]{1}
\bitheader{0} \\ \bitbox{1}{uint8}
\end{bytefield}}}
\\ \hline
\raisebox{-1ex}{
{\begin{bytefield}[endianness=little,bitwidth=5em]{2}
\bitheader{0,1} \\ \bitbox{1}{MSB} & \bitbox{1}{LSB}
\end{bytefield}}}
\end{tabular}
which produces the error
! Extra alignment tab has been changed to \cr.
<template> \endtemplate
l.13 \end{bytefield}}}
If the second \raisebox
is removed, the first line's layout is correct, the second is not: