2

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): enter image description here

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

4

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}%
  \hspace{-\fboxrule}\addtocounter{bitnum}{-1}\endgroup\ignorespaces}
\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}

enter image description here

| improve this answer | |
  • 1
    Thanks, I was also able to use your code inside a figure. Very nice! – a_bet Mar 13 at 13:23
0

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: enter image description here

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.