彩色自定义字节字段

彩色自定义字节字段

我制作了一个bytefield包(见图),我想用该字段为该字段着色256-bit RSA Signature

enter image description here

这是我使用的代码(来自另一个问题):

\documentclass[10pt,a4paper]{article}
\usepackage[table, usenames,dvips, dvipsnames]{xcolor}
\usepackage{bytefield}

\begin{document}
    \begin{bytefield}{32}
        \bitheader{0,2,4,16, 31} \\
        \bitbox{2}{12} & \bitbox{2}{\textcolor{WildStrawberry}{65}} & \bitbox[lrt]{28}{}\\
        \wordbox[lr]{1}{\textcolor{WildStrawberry}{65}-bit EC Public Key}\\
        \bitbox[lrb]{5}{} & \bitbox[lrt]{27}{}\\
        \wordbox[lr]{3}{256-bit RSA Signature} \\
        \bitbox[lrb]{5}{} & \bitbox[lt]{27}{}\\
    \end{bytefield}
\end{document}

我见过给包中的字段上色的(不太常见的)技巧bytefield。他们创建了一个命令来添加一个彩色框,如下所示:

\newcommand{\colorbitbox}[3]{%
 \rlap{\bitbox{#2}{\color{#1}\rule{\width}{\height}}}%
 \bitbox{#2}{#3}
}%

它适用于古典字段,但\colorbitbox创建时不允许\bytefiled使用类似的选项[lrb]

我该如何对分成多行的字段执行此操作?

答案1

很容易修改\colorbitbox以接受可选参数并声明等效的\colorwordbox

问题是结果并不理想,您可以在下面的上图中看到。宽度word字段的原始定义无法仅绘制其边框的某些部分,而在本例中这是必需的。

因此,我的最佳解决方案(第二个字节场代码)是手动将每个字节划分wordbox为所需的数量bitbox。结果是第二个数字。

\documentclass[10pt,a4paper]{article}
\usepackage[table, usenames, dvipsnames]{xcolor}
\usepackage{bytefield}
\usepackage{graphicx}

\newcommand{\colorbitbox}[4][]{%
\rlap{\bitbox[#1]{#3}{\color{#2}\rule{\width}{\height}}}%
\bitbox[#1]{#3}{#4}}

\newcommand{\colorwordbox}[4][]{%
\rlap{\wordbox[#1]{#3}{\color{#2}\rule{\width}{\height}}}%
\wordbox[#1]{#3}{#4}}

\definecolor{lightcyan}{rgb}{0.84,1,1}
\definecolor{lightgreen}{rgb}{0.64,1,0.71}
\definecolor{lightred}{rgb}{1,0.7,0.71}

\begin{document}
    \begin{bytefield}{32}
        \bitheader{0,2,4,16, 31} \\
        \bitbox{2}{12} & \bitbox{2}{\textcolor{WildStrawberry}{65}} 
              & \bitbox[lrt]{28}{}\\
        \wordbox[lr]{1}{\textcolor{WildStrawberry}{65}-bit EC Public Key}\\
        \bitbox[lrb]{5}{} & \colorbitbox[lrt]{lightcyan}{27}{}\\
        \colorwordbox[lr]{lightcyan}{3}{256-bit RSA Signature} \\
        \colorbitbox[lrb]{lightcyan}{5}{} & \bitbox[lt]{27}{}\\
    \end{bytefield}

    \begin{bytefield}{32}
        \bitheader{0,2,4,16, 31} \\
        \bitbox{2}{12} & \bitbox{2}{\textcolor{WildStrawberry}{65}} 
              & \bitbox[lrt]{28}{}\\
        \wordbox[lr]{1}{\textcolor{WildStrawberry}{65}-bit EC Public Key}\\
        \bitbox[lrb]{5}{} & \colorbitbox[lrt]{lightcyan}{27}{}\\
        \colorbitbox[lt]{lightcyan}{5}{}\colorbitbox[r]{lightcyan}{27}{} \\
        \colorbitbox[lr]{lightcyan}{32}{256-bit RSA Signature} \\
        \colorbitbox[l]{lightcyan}{5}{}\colorbitbox[br]{lightcyan}{27}{} \\
        \colorbitbox[lrb]{lightcyan}{5}{} & \bitbox[lt]{27}{}\\
    \end{bytefield}
\end{document}

enter image description here

相关内容