幅を制限しようとしたときにバイトフィールド パッケージを使用した算術オーバーフロー エラーが発生しました

幅を制限しようとしたときにバイトフィールド パッケージを使用した算術オーバーフロー エラーが発生しました

私は、このパッケージを多用したドキュメントを作成しようとしていますbytefieldが、64 ビット幅にする必要があるフィールドに対して適切な解決策が存在しないという状況に陥っています (ドキュメントにもそのような例が示されていません)。さっそく、結果を示します。

バイトフィールド幅の問題

ご覧のとおり、64ビット値の幅はページからはみ出しています。私は、bitwidthドキュメントに記載されているように、オプションパラメータを使用してこれを制限しようとしました(次の例のように) 。この回答の質問の引数を与え0.8\textwidth、そこから調整しますが、そうすると「算術オーバーフロー」エラーが発生します。 の幅を制限する方法を誰か知っていますか?フィールド全体、または少なくともbytefieldページ自体よりも幅が広くならないフィールドを生成するように強制しますか?

最小限の動作例のコードは次のとおりです。

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

エラーを生成する動作しないコードは次のとおりです。中括弧で囲んでもエラーは軽減されません。

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

また、賢明なアドバイスですが、私はまだ (ゆっくりと) TeX のコツをつかんでいるところなので、自己満足のスキルは「オンラインで解決策を探し、誰かがそれを実装していることを期待する」程度にとどまっています。潜在的な回答を少し分解していただく必要があるかもしれません。

参考になれば幸いですが、問題の環境は MacTex 2015 (TeXLive-2015) です。コードは TeXstudio 2.10.4 を使用して構築されました。

答え1

\resizeboxパッケージで試すことができます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}

ここに画像の説明を入力してください

それ以外の場合は、同じサイズを維持します。

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

\centerlineこれは LaTeX コマンドの中では最善のものではありません。(ただし、ここではこれが唯一のコマンドなので問題ありませんcenter)。

ここに画像の説明を入力してください

アップデート:

バイトフィールド ボックスの深さが意外に深かったため、少し試行錯誤が必要でした。また、垂直方向のずれを避けるために幅を少し減らす必要がある理由も、私にはよくわかりません。

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

ここに画像の説明を入力してください

答え2

ビット用に確保された幅はビット数で乗算される必要があるため、次のような数字になります。

bitwidth=0.015\textwidth

以下であれば、動作する可能性が高くなります (showframe例のみのオプション):

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

ここに画像の説明を入力してください

関連情報