如何为网格的每个框插入一个计数器?在下面的例子中,我只是表示一个带有符号、尾数和指数的 32 位浮点数,并且需要将 0-31 作为 32 位的计数。
\begin{figure}[ht!]
\centering
\begin{tikzpicture}
\fill[mplc3!20] (0,0) rectangle (.5,.5);
\fill[mplc0!50] (.5,0) rectangle (4.5,.5);
\fill[mplc1!50] (4.5,0) rectangle (16.5,.5);
\draw[step=.5, thick, fill=mplc2!20] (0,0) grid (16.5,.5);
\node at (0.25, -.25){\textcolor{mplc3}{sign}};
\node at (2.25, .75){\textcolor{mplc0}{exponent}};
\node at (10, -.25){\textcolor{mplc1}{mantissa}};
\end{tikzpicture}
\centering
\caption{Name}%
\label{fime}
\end{figure}
答案1
以下示例取自bytefield
文档。
\documentclass{article}
\usepackage{bytefield}
\usepackage{lmodern}
\usepackage{xcolor}
\usepackage{graphicx}
\begin{document}
\definecolor{lightcyan}{rgb}{0.84,1,1}
\definecolor{lightgreen}{rgb}{0.64,1,0.71}
\definecolor{lightred}{rgb}{1,0.7,0.71}
\begin{bytefield}[bitheight=\widthof{~Sign~},
boxformatting={\centering\small}]{32}
\bitheader[endianness=big]{31,23,0} \\
\bitbox{1}[bgcolor=lightcyan]{\rotatebox{90}{Sign}} &
\bitbox{8}[bgcolor=lightgreen]{Exponent} &
\bitbox{23}[bgcolor=lightred]{Mantissa}
\end{bytefield}
\end{document}