代码在位框内的规则未对齐几乎可以带我去所有我需要去的地方,但我还希望能够着色\bitboxes*
。
我尝试了@egreg的这个变体\colorbitbox
:
\newcommand{\colorbitboxes*}[3]{%
\sbox0{\bitboxes*{#2}{#3}}%
\makebox[0pt][l]{\textcolor{#1}{\rule[-\dp0]{\wd0}{\ht0}}}%
\bitboxes*{#2}{#3}%
}
但不幸的是,当我尝试使用它时,它失败了:You can't use ‘macro parameter character #’ in internal vertical mode.
我也不知道如何传递参数,比如[ltb]
,\colorbitbox
这是获得我想要的输出的另一种方法,尽管更冗长,因为我有 12 位我想要的。当我尝试这样做时,它说! Missing number, treated as zero.
我知道一些 LaTeX,但这对我来说太深奥了,所以我很困惑,如能得到任何帮助我将非常感谢!
为了扩展我的评论,@Mike 的回答与我的字节字段如下所示(下面的代码):
\newcommand{\baselinealign}[1]{%
\centering
\strut#1%
}
\begin{bytefield}[bitwidth=1.9em, leftcurly=., leftcurlyspace=0pt, boxformatting={\baselinealign}]{16}
\hexhead \\
\begin{leftwordgroup}{\tiny\bfseries 00}
\colorbitbox{lightgreen}{1}{\tt 11} & \colorbitbox{lightgreen}{4}{\tt 872349ae} &
\colorbitbox{yellow}{1}{\tt 11} & \colorbitbox{yellow}{4}{$TxID$} &
\colorbitbox{lightred}{1}{\tt 10} & \colorbitbox{lightred}{2}{$type$} &
\colorbitbox{lightcyan}{1}{\tt 0f} & \colorbitbox{lightcyan}{1}{$n$} &
\colorbitbox{lightpurple}{1}{\tt 14}
\end{leftwordgroup} \\
\begin{leftwordgroup}{\tiny\bfseries 10}
\colorbitbox{lightpurple}{4}{{\tt 0000000c}\small{ (12)}} &
\colorbitbox[lbt]{lightpurple}{1}{$t_1$} & \colorbitbox[bt]{lightpurple}{1}{$t_2$} &
\colorbitbox[bt]{lightpurple}{1}{$t_3$} & \colorbitbox[bt]{lightpurple}{1}{$t_4$} &
\colorbitbox[bt]{lightpurple}{1}{$t_5$} & \colorbitbox[bt]{lightpurple}{1}{$t_6$} &
\colorbitbox[bt]{lightpurple}{1}{$t_7$} & \colorbitbox[bt]{lightpurple}{1}{$t_8$} &
\colorbitbox[bt]{lightpurple}{1}{$t_9$} & \colorbitbox[bt]{lightpurple}{1}{$t_{10}$} &
\colorbitbox[bt]{lightpurple}{1}{$t_{11}$} & \colorbitbox[rbt]{lightpurple}{1}{$t_{12}$}
\end{leftwordgroup} \\
\begin{leftwordgroup}{}
\wordbox[lrt]{1}{Arguments} \\
\skippedwords \\
\wordbox[lrb]{1}{}
\end{leftwordgroup}
\end{bytefield}
答案1
曾几何时,我想到了这个,到目前为止效果很好:
\documentclass{article}
\usepackage{bytefield}
\usepackage{xcolor}
\newcommand{\colorwordbox}[4][rlbt]{%
\rlap{\wordbox[#1]{#3}{\color{#2}\rule{\dimexpr\width-0.4pt}{\dimexpr\height-0.4pt}}}%
\wordbox[#1]{#3}{#4}}
\newcommand{\colorbitbox}[4][lrbt]{%
\rlap{\bitbox[#1]{#3}{\color{#2}\rule{\dimexpr\width-0.4pt}{\dimexpr\height-0.4pt}}}%
\bitbox[#1]{#3}{#4}}
\begin{document}
\begin{bytefield}[endianness=big,
bitwidth=3.5em]{8}
\bitheader{0-7}\\
\colorwordbox{green}{1}{a green byte}\\
\wordbox[lrb]{1}{a byte without color}\\
\colorwordbox[]{red}{1}{a red byte with no frame}\\
\colorbitbox{green}{3}{3 bits} &
\bitbox{1}{bit 4} &
\colorbitbox{green}{1}{bit 3} &
\colorbitbox{red}{1}{bit 2} &
\colorbitbox{green}{2}{2 bits}\\
\bitbox{1}{bit 7} &
\bitbox{1}{bit 6} &
\colorbitbox[]{cyan}{4}{4 bits, no frame} &
\bitbox{1}{bit 1} &
\colorbitbox{cyan}{1}{bit 0}
\end{bytefield}
\end{document}
缺点:由于没有框架\dimexpr\width-0.4pt
,\dimexpr\height-0.4pt
彩色区域有点太短。但如果没有它,它们会部分覆盖相邻的框架。