3

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: enter image description here

  • 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. – egreg Jun 16 '16 at 9:18
4

You just need to brace the bytefield environment:

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

enter image description here

Addendum

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}
        \bitheader{0} \\ \bitbox{1}{uint8}
        \end{bytefield}}
    \\ \hline
    \raisebox{-1ex}[5ex][1.5ex]{% <---- HERE
        \begin{bytefield}[endianness=little,bitwidth=5em]{2}
        \bitheader{0,1} \\ \bitbox{1}{MSB} \bitbox{1}{LSB}
        \end{bytefield}}
\end{tabular}
\end{document}

enter image description here

  • I know this violates the rules for comments, but egreg, you are awesome! – Twonky Jun 16 '16 at 9:34
  • @Twonky An esteemed member of the community maintains that my only ability with TeX is spotting missing %'s. Maybe he's right. ;-) – egreg Jun 16 '16 at 9:35

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.