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.
1 Answers
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
{\addcytoks{\makebox[\wd\lettwd]{##1}}}
{\processtoks{##1}}
{\addcytoks{##1}}
{\addcytoks{\makebox[\wd\lettwd]{##1}}}
\begin{document}
\rmhex 0123456789\endrmhex
\rmhex 2356 FFB A\endrmhex
DDDDDDDDDD
\end{document}
- 237,551
-
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. https://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 '20 at 08:43
-
@larkey, that's exactly what I'm talking about, thanks for clarifying! – Reuben Thomas May 11 '20 at 10:53
-
1Thanks 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 '20 at 11:03

listings) is discussed here – Chris H May 11 '20 at 08:30\textttfor 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 '20 at 08:32