# Good way/example to depict a digital register in LaTeX?

I'm writing technical docs for a RISC-V processor. This requires writing down a lot of small tables like this one (which are the computer's register with every field acronym specified):

I may do this using table, but I see that in my reference manual reference manual they used a figure instead. Any advice/example to fast draw a bunch of these?

Many thanks in advance for any hint

• There is no problem in using tabular inside a figure environment. Mar 12, 2020 at 15:46
• @jsbibra thanks for the suggestion. The register package is nice and I'm trying it out. Maybe we could improve the answer by adding it Mar 13, 2020 at 13:56
• @jsbibra do you now if with the register package is possible to define a reg inside a figure environment? The doc does not mention it Mar 13, 2020 at 14:06

A homebrew solution. The length of \bitwidth can be changed to alter the scale of horizontal buffer space around each entry.

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\newlength\bitwidth
\setlength\bitwidth{5pt}
\newcounter{bitnum}
\newcommand\bitbox[2][\thebitnum]{\setcounter{bitnum}{#1}%
\begingroup\fboxsep=1pt\relax\stackunder{\stackon{\fbox{%
\hspace{\dimexpr\wd0+.5\bitwidth}#2%
\hspace{\dimexpr\wd0+.5\bitwidth}\strut}}{#1}}{1}%
\newcommand\bytebox[3][\thebitnum]{%
\setcounter{bitnum}{#1}\begingroup\fboxsep=1pt\relax\setbox0=\hbox{#3}%
\stackunder{\def\stackalignment{r}\stackon[0pt]{\def\stackalignment{l}%
\stackon{\fbox{\makebox[\wd0+#2\bitwidth]{#3\strut}}}{\smash{~#1}}}%
{\the\numexpr#1-#2+1~}}{#2}\hspace{-\fboxrule}%
\endgroup\setcounter{bitnum}{\numexpr#1-#2}\ignorespaces}
\newcommand\continuebox{\begingroup\fboxsep=1pt\relax%
\stackunder[\fboxsep]{\stackon[\fboxsep]{\strut}{\rule{8pt}{\fboxrule}}}%
{\rule{8pt}{\fboxrule}}\endgroup%
}
\begin{document}
\bitbox[31]{SD}
\bytebox{8}{WPRI}
\bitbox{TSR}
\bitbox{TW}
\bytebox{2}{MPP[1:0]}
\bytebox{2}{WPRI}
\continuebox\dots\continuebox
\bytebox[15]{16}{XS[15:0]}
\end{document}


• Thanks, I was also able to use your code inside a figure. Very nice! Mar 13, 2020 at 13:23

After a few days of working with it I can definitely suggest to use the Register Package from Matthew Lovell. It is a complete solution offering good support for documenting registers in a compact yet readable way.

Here's an example I made in Overleaf:

This very simple, but much more fancy stuff (reset values, colors...) can be added.