我正在嘗試起草一份文檔,該文檔大量使用了該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
of 套件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}