# Tabular hex numerals?

Is there a non-typewriter font that I can use for hex numbers with tabular numerals, i.e. 0–F are the same width, so they line up in columns? I can't find anything by searching. I imagine that if not I could work up a hacky macro to approximate it by putting each numeral in a box of the same width.

• That sort of defines a typewriter font. However, there are ways to allocate the glyphs of non-typewriter fonts to constant-width boxes. Such ways would be embodied in a macro. Is a macro approach OK, or do you need this characteristic in the underlying font? – Steven B. Segletes May 10 at 22:33
• @StevenB.Segletes, monospacing is only one definition of a typewriter font. Another common one (probably more common) is a font that looks like it came from a typewriter. The former is what the OP wants and doesn't require the latter. In particular there are plenty of sans-serif monospaced fonts; using one (with listings) is discussed here – Chris H May 11 at 8:30
• Your requirement seems to be for monospacing. If you're not using \texttt for anything else, use another monospaced font might be of interest. Even if you are the links in some of the answers may be helpful. – Chris H May 11 at 8:32

If you want the font to, by its design, produce equal width letters, that is the very definition of typewriter font. If that is what you seek, you need just look through a library of such fonts for one that suits.

But if you are open to a macro or environment approach to solving this problem, here I use tokcycle to build the \rmhex pseudo-environment, which will produce equal-spaced digits. The spacing is chosen to match the widest glyph of the document's default font in the range 0-9,A-F, which covers the hexadecimal range that seemed to be of interest to the OP.

In the MWE below, I show the result. While the spacing may seem wide, it is set to the width of the D, which is the widest glyph in Computer Modern over the range 0-9,A-F. The environment works by applying a fixed width \makebox to each token in the environment.

\documentclass{article}
\usepackage{tokcycle}
\newsavebox\lettwd
\savebox\lettwd{{\ooalign{0\cr A\cr B\cr C\cr D\cr E\cr F}}}
\tokcycleenvironment\rmhex
{\processtoks{##1}}