
Я пытаюсь составить документ, который очень интенсивно использует пакет, 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}