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.

  • 2
    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.

\savebox\lettwd{{\ooalign{0\cr A\cr B\cr C\cr D\cr E\cr F}}}
\rmhex 0123456789\endrmhex

\rmhex 2356 FFB A\endrmhex


enter image description here

| improve this answer | |
  • No, they want a proportional font, not necessarily typewriter. Fonts like Palatino or MinionPro have OpenType features to be monospaced or at least have a subset (eg. decimal numerals) proportional, eg. tex.stackexchange.com/a/99702/90407 I don't know whether there are non-typewriter fonts that allow also non-decimal numerals to be proportional... – ljrk May 11 at 8:43
  • @larkey, that's exactly what I'm talking about, thanks for clarifying! – Reuben Thomas May 11 at 10:53
  • 1
    Thanks very much, that's exactly what I was after, and the advantage of a macro is that it works with any font. – Reuben Thomas May 11 at 11:03

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.