# bytefield inside tabular

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}
\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.

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}
\end{bytefield}}}
\\ \hline
\raisebox{-1ex}{
{\begin{bytefield}[endianness=little,bitwidth=5em]{2}
\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:

• I added a fix also for your addendum, though it was completely unrelated. Please, avoid modifying questions so as to invalidate existing answers. And ensure the example code is compilable: the one you added doesn't. Jun 16, 2016 at 9:18

You just need to brace the bytefield environment:

\documentclass[border=2mm]{standalone}
\usepackage{bytefield}

\begin{document}

\begin{tabular}{c}
{\begin{bytefield}{2}
\end{bytefield}}
\end{tabular}

\end{document}


There is no misalignment if you properly protect the end-of-line; if you have bytefield inside \raisebox, there's no need of the additional braces, already provided by \raisebox (implicitly), but they do no harm.

\documentclass[border=2mm]{standalone}
\usepackage{bytefield}

\begin{document}
\begin{tabular}{l}\hline
\raisebox{-1ex}[5ex][1.5ex]{% <---- HERE
\begin{bytefield}[endianness=big,bitwidth=5em]{1}

• @Twonky An esteemed member of the community maintains that my only ability with TeX is spotting missing %'s. Maybe he's right. ;-) Jun 16, 2016 at 9:35