Bytefield 能够处理奇数大小的字段(示例取自文档):
\begin{bytefield}{16}
\bitheader{0,7,8,15} \\
\bitbox{8}{8-bit field} & \bitbox[lrt]{8}{} \\
\wordbox[lrb]{1}{24-bit field}
\end{bytefield}
我遇到了这种问题,但字段大小小于图形的宽度。这里,FCCS 字段为 5 位宽,并被截断为两行(我删除了边框以使其清晰):
\begin{bytefield}[bitwidth=2em]{8}
\bitheader{0-7} \\
\bitbox{1}{---} &
\bitbox{3}{DT} &
\bitbox[ltb]{4}{FCCS} \\
\bitbox[rtb]{1}{} &
\bitbox{6}{ConvZeros} &
\bitbox{1}{\color{lightgray}\rule{\width}{\height}} \\
\end{bytefield}
有没有办法更清楚地表明该字段在下一行继续?例如,在第一行的实际结尾和第二行的实际开头添加“~”?
答案1
一种方法是改变字节字段绘制命令,有条件地在字段的开始或结束处添加波浪号。
在下面的 MWE 中,这是通过声明一个新命令来完成的\continuebox
,该命令接受一个额外的参数来表示右侧或左侧的波浪号,并设置一个布尔值来指示需要添加波浪号。
使用该包,在内部命令的xpatch
中间插入一些代码来检查布尔值,并在与正常框相同的位置绘制一个框,其中的字段标签带有波浪号,可以在字段的左侧,也可以在右侧使用。\draw@bit@picture
bytefield
\raggedleft
最后,重新定义常规\bitbox
命令以将布尔值设置为 false,以防止打印普通字节字段的波浪号。
0.3em
波浪号左侧或右侧留有一点水平空间( ),以确保其适合框。
梅威瑟:
\documentclass{article}
\usepackage{xcolor}
\usepackage{bytefield}
\usepackage{xpatch}
\makeatletter
% boolean to check if tilde is needed
\newif\ifbitbox@continue
% boolean to put tilde at start or end of field
\newif\ifbitbox@continueright
% new command with extra argument to put tilde
\DeclareRobustCommand{\continuebox}[4][lrtb]{%
% set boolean for drawing tilde to true
\bitbox@continuetrue%
% set position boolean depending on argument #4
\ifx#4r\bitbox@continuerighttrue\else\bitbox@continuerightfalse\fi%
% code for drawing the field copied from \bitbox
\setlength{\units@wide}{\bf@bitwidth * #2}%
\bf@parse@bitbox@arg{#1}%
\draw@bit@picture{\strip@pt\units@wide}{\strip@pt\bf@bitheight}{#3}}
% original \bitbox command modified to set boolean to false
\DeclareRobustCommand{\bitbox}[3][lrtb]{%
\setlength{\units@wide}{\bf@bitwidth * #2}%
\bf@parse@bitbox@arg{#1}%
% set boolean to false
\bitbox@continuefalse%
\draw@bit@picture{\strip@pt\units@wide}{\strip@pt\bf@bitheight}{#3}}
% add drawing tilde to internal field drawing command
% put box with tilde on top of regular box
% align right or left depending on boolean for position
\xpatchcmd{\draw@bit@picture}{\ifbitbox@top}{\ifbitbox@continue
\put(0,0){\makebox(\strip@pt\units@wide,\strip@pt\bf@bitheight){\parbox{\strip@pt\units@wide\unitlength}{%
\ifbitbox@continueright\raggedleft$\sim\hskip 0.3em$\else$\hskip 0.3em\sim$\fi\par}}}%
\fi%
\ifbitbox@top}{}{}
\makeatother
\begin{document}
\begin{bytefield}[bitwidth=2em]{8}
\bitheader{0-7} \\
\bitbox{1}{---} &
\bitbox{3}{DT} &
%\bitbox[ltb]{4}{FCCS} \\
%\bitbox[rtb]{1}{} &
\continuebox[ltb]{4}{FCCS}{r} \\
\continuebox[rtb]{1}{}{l} &
\bitbox{6}{ConvZeros} &
\bitbox{1}{\color{lightgray}\rule{\width}{\height}} \\
\end{bytefield}
\end{document}
结果: