Erro de estouro aritmético usando o pacote bytefield ao tentar restringir a largura

Erro de estouro aritmético usando o pacote bytefield ao tentar restringir a largura

Estou tentando redigir um documento que faz uso intenso do bytefieldpacote e me deparo com a situação de que parece que não existe uma boa solução para campos que precisam ter 64 bits de largura (mesmo a documentação não mostra esses exemplos!). Sem mais delongas, aqui está o resultado:

Problema com largura do campo de bytes

Como você pode ver, a largura do valor de 64 bits sai da página. Tentei restringir isso com o bitwidthparâmetro opcional conforme descrito na documentação (como seguira pergunta desta respostapara fornecer um argumento de 0.8\textwidth, ajustando a partir daí, mas isso gera um erro de "estouro aritmético". Alguém sabe como restringir a largura dotodo o campo em si, ou pelo menos forçar bytefielda produção de um campo que não pode ser mais largo que a própria página?

Aqui está o código para o exemplo mínimo de trabalho:

\documentclass[10pt]{extreport}
\usepackage[margin=2.0cm,a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{bytefield}

\begin{document}
    \noindent
    An \texttt{unsigned word} is defined as a 16-bit or two-octet quantity, having the range \texttt{[0, 65535]}: \\

    \begin{center}
        \begin{bytefield}[endianness=big]{16}
            \bitheader{15, 7, 0}                \\
            \bitbox{16}{\texttt{unsigned word}} \\
        \end{bytefield}
    \end{center}

    An \texttt{unsigned word} is addressable as an 2-size array of bytes, where \texttt{byte[0]} corresponds to the most-significant byte in the word (the \textit{high byte}) and \texttt{byte[1]} corresponds to the least-significant byte in the word (the \textit{low byte}). \\

    \vspace{5pt}
    \hrule
    \vspace{15pt}

    \noindent
    An \texttt{unsigned doubleword} is defined as a 32-bit or four-octet quantity, having the range \texttt{[0, 4294967295]}: \\

    \begin{center}
        \begin{bytefield}[endianness=big]{32}
            \bitheader{31, 23, 15, 7, 0}                \\
            \bitbox{32}{\texttt{unsigned doubleword}}   \\
        \end{bytefield}
    \end{center}

    An \texttt{unsigned doubleword} is addressable as an 4-size array of bytes, where \texttt{byte[0]} corresponds to the most-significant byte in the doubleword (the \textit{high byte}) and \texttt{byte[3]} corresponds to the least-significant byte in the doubleword (the \textit{low byte}). \\

    \vspace{5pt}
    \hrule
    \vspace{15pt}

    \noindent
    An \texttt{unsigned quadword} is defined as a 64-bit or eight-octet quantity, having the range \texttt{[0, 18446744073709551615]}: \\

    \begin{center}
        \begin{bytefield}[endianness=big]{64}
            \bitheader{63, 55, 47, 39, 31, 23, 15, 7, 0}    \\
            \bitbox{64}{\texttt{unsigned quadword}}         \\
        \end{bytefield}
    \end{center}

    An \texttt{unsigned quadword} is addressable as an 8-size array of bytes, where \texttt{byte[0]} corresponds to the most-significant byte in the quadword (the \textit{high byte}) and \texttt{byte[7]} corresponds to the least-significant byte in the quadword (the \textit{low byte}). \\
\end{document}

O código que não funciona que gera o erro é o seguinte - colocá-lo entre chaves não alivia o erro:

\begin{center}
    \begin{bytefield}[endianness=big, bitwidth=0.8\textwidth]{64}
        \bitheader{63, 55, 47, 39, 31, 23, 15, 7, 0}    \\
        \bitbox{64}{\texttt{unsigned quadword}}         \\
    \end{bytefield}
\end{center}

Além disso, palavra para o sábio - ainda estou (lentamente) aprendendo o TeX, então minha habilidade de autoatendimento ainda é um tanto limitada a "procurar online por uma solução, espero que alguém a tenha implementado"; você pode ter que ajudar a detalhar um pouco uma resposta potencial para mim.

O ambiente em questão, se ajudar, é o MacTex 2015 (TeXLive-2015); o código foi construído usando TeXstudio 2.10.4.

Responder1

Você pode tentar com \resizeboxpackage graphicx.

\documentclass[10pt]{extreport}
\usepackage[margin=2.0cm,a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{bytefield}
\usepackage{graphicx}
\begin{document}
    \noindent
    An \texttt{unsigned word} is defined as a 16-bit or two-octet quantity, having the range \texttt{[0, 65535]}: \\

    \begin{center}
        \begin{bytefield}[endianness=big]{16}
            \bitheader{15, 7, 0}                \\
            \bitbox{16}{\texttt{unsigned word}} \\
        \end{bytefield}
    \end{center}

    An \texttt{unsigned word} is addressable as an 2-size array of bytes, where \texttt{byte[0]} corresponds to the most-significant byte in the word (the \textit{high byte}) and \texttt{byte[1]} corresponds to the least-significant byte in the word (the \textit{low byte}). \\

    \vspace{5pt}
    \hrule
    \vspace{15pt}

    \noindent
    An \texttt{unsigned doubleword} is defined as a 32-bit or four-octet quantity, having the range \texttt{[0, 4294967295]}: \\

    \begin{center}
        \begin{bytefield}[endianness=big]{32}
            \bitheader{31, 23, 15, 7, 0}                \\
            \bitbox{32}{\texttt{unsigned doubleword}}   \\
        \end{bytefield}
    \end{center}

    An \texttt{unsigned doubleword} is addressable as an 4-size array of bytes, where \texttt{byte[0]} corresponds to the most-significant byte in the doubleword (the \textit{high byte}) and \texttt{byte[3]} corresponds to the least-significant byte in the doubleword (the \textit{low byte}). \\

    \vspace{5pt}
    \hrule
    \vspace{15pt}

    \noindent
    An \texttt{unsigned quadword} is defined as a 64-bit or eight-octet quantity, having the range \texttt{[0, 18446744073709551615]}: \\

    \begin{center}
        \resizebox{1.0\linewidth}{\height}{\begin{bytefield}[endianness=big]{64}
            \bitheader{63, 55, 47, 39, 31, 23, 15, 7, 0}    \\
            \bitbox{64}{\texttt{unsigned quadword}}         \\
        \end{bytefield}}
    \end{center}

    An \texttt{unsigned quadword} is addressable as an 8-size array of bytes, where \texttt{byte[0]} corresponds to the most-significant byte in the quadword (the \textit{high byte}) and \texttt{byte[7]} corresponds to the least-significant byte in the quadword (the \textit{low byte}). \\
\end{document}

insira a descrição da imagem aqui

Caso contrário, mantendo o mesmo tamanho:

\begin{center}
    \centerline{\begin{bytefield}[endianness=big]{64}
        \bitheader{63, 55, 47, 39, 31, 23, 15, 7, 0}    \\
        \bitbox{64}{\texttt{unsigned quadword}}         \\
    \end{bytefield}}
\end{center}

embora \centerlinenão seja o melhor dos comandos LaTeX. (mas está bom aqui, como a única coisa no centermaterial).

insira a descrição da imagem aqui

Atualizar:

precisei de um pouco de tentativa e erro devido à profundidade surpreendente da caixa do campo de bytes. Além disso, não está totalmente claro para mim por que preciso reduzir um pouquinho a largura para evitar um deslocamento vertical.

\begin{center}
    \mbox{\resizebox{.9999\linewidth}{\height}{%
          \begin{bytefield}[endianness=big]{64}
              \bitheader{63, 55, 47, 39, 31, 23, 15, 7, 0}    \\
              \bitbox{64}{}         \\
            \end{bytefield}}%
\kern-\linewidth
     \makebox[\linewidth]{\raisebox{4ex}{\texttt{unsigned quadword}}}%
          }
\end{center}

insira a descrição da imagem aqui

Responder2

A largura reservada para um bit deve ser multiplicada pelo número de bits, então uma figura como

bitwidth=0.015\textwidth

ou menos é mais provável que funcione (opção showframeapenas para exemplo):

\documentclass[10pt]{extreport}
\usepackage[margin=2.0cm,a4paper,showframe]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{bytefield}

\begin{document}
An \texttt{unsigned quadword} is defined as a 64-bit or quantity, in the range
\texttt{[0, 18446744073709551615]}:
\begin{center}
\begin{bytefield}[endianness=big,bitwidth=0.015\textwidth]{64}
  \bitheader{63, 55, 47, 39, 31, 23, 15, 7, 0}    \\
  \bitbox{64}{\texttt{unsigned quadword}}         \\
  \end{bytefield}
\end{center}

\end{document}

insira a descrição da imagem aqui

informação relacionada