# Using bytefield in standalone class cuts the field numbers

To me, the described behaviour appears to be a bytefield v2.2 package bug. Maybe I'm getting things wrong and standalone v1.2 is bugged as well. Or it's just me doing things wrong.

Typesetting this minimal example

\documentclass{standalone}
\usepackage{bytefield}
\begin{document}
\begin{bytefield}[bitwidth=2.1em]{2}
\end{bytefield}
\end{document}


using pdflatex produces a too tightly cropped bitfield:

Top border is much too tight, other borders are a bit too tight as they cut a framed pixel. I consider this a bytefield bug and tried to find a workaround.

As suggested in this question, the standalone border can be increased which reveals the bytefield numbers at least partly:

\documentclass[border=1pt 0pt 1pt 10cm]{standalone}


produces this:

which solves the problem at bottom/left/right border, but not at the top border. This appears to be a standalone bug.

Using \documentclass[border=2mm]{standalone} extends all borders as expected. The current workaround would be to extend all borders by approximately 2mm to make the bytefield numbers visible.

For me, this workaroud is very unfortunate, since I am creating lots of PDFs using the standalone class in an automated environment - only a few of them being bytefields. Thus, I would have to increase all borders since the bytefield environment does not accept border as optional parameter.

Is any other workaround known?

The problem here is that the index numbers on top are not part of the bounding box of the bytefield table. You can see this by just using a bytefield environment inside a normal document and add \frame{...} around it. The resulting frame will also cut the index numbers.

This is caused by bytefield, I guess because the including picture environment doesn't take the index number height into account.

There is nothing standalone or any other TeX tool can do afterward as the official size is not determined by the "ink" but by the official bounding box. Only rendering tools like ghostscript can recalculate the corrent bounding box by looking at the produced "ink".

As a solution simply add a border around it. Your code example does not work because you need to add the numbers into braces to protect the spaces from the option processing code of \documentclass.

The following works (note that 0.5 (=0.5bp; big points) is the default border):

\documentclass[border={.5 .5 .5 2mm}]{standalone}
\usepackage{bytefield}
\begin{document}
\begin{bytefield}[bitwidth=2.1em]{2}