3

This is a follow-up to Is this horizontal alignment correct?. In short, I would to print the text 100 µm visually centered on a scale bar. The problem with this is the digit 1 has the same wide bounding box as, e.g., the digit 5 (probably to simplify alignment of numerical material), so that the bounding box takes more space than the character itself. As a result, horizontal centering is off.

Is there a variant of the digit 1 with a tighter, more "within-text-like" bounding box? Can I easily build one?

bers
  • 5,404
  • To me, it sounds like what you're after is a so-called "proportionately spaced", rather than "fixed spaced", digit 1. Please tell us which text font and math fonts you use. – Mico Nov 07 '20 at 06:20

1 Answers1

3

Is there a variant of the digit 1 with a tighter, more "within-text-like" bounding box?

It sounds like you're looking for proportionally spaced, rather than the usual fixed spaced, numerals.

Can I easily build one?

This depends on which font and which LaTeX compiler you employ. Your mission is fairly easy to accomplish if you employ either XeLaTeX or LuaLaTeX, rather than the default pdfLaTeX, to compile your documents. Compare the first and second tikz pictures below; the effect of switching to a proportionally-spaced numeral 1 is definitely visible, but it is quite subtle.

For maximum visual effect, you may actually want to switch to so-called "oldstyle" numerals; see the third tikz picture below.

enter image description here

% !TEX TS-program = lualatex
%    or: !TEX TS-program = xelatex
\documentclass{article}

\usepackage{fontspec} % Set the default font (fixed-width lining-type numerals): \setmainfont{Latin Modern Roman} % Same font family, but with proportionally-spaced numerals: \newfontfamily\LMPropNums{Latin Modern Roman}[Numbers={Proportional}] % Same font family, but with oldstyle numerals: \newfontfamily\LMOldStyle{Latin Modern Roman}[Numbers=OldStyle]

\newcommand\POne{{\LMPropNums 1}} % just the numeral "1"

\usepackage{tikz} \usepackage{siunitx}

\begin{document}

\begin{tabular}{@{}ll@{}} 111 & fixed spaced \ \LMPropNums 111 & proportionally spaced \ 000 & fixed spaced \ \LMPropNums 000 & proportionally spaced \end{tabular}

\begin{tikzpicture} \draw (0, 0) node (image){\includegraphics[width=1.1cm]{example-image} }; \draw[red, x={(image.south east)}, y={(image.north west)}] (0.5, 0.5) node (text){\SI{100}{\micro\meter} }; \end{tikzpicture}

% Use a proportionally-spaced digit "1": \begin{tikzpicture} \draw (0, 0) node (image){\includegraphics[width=1.1cm]{example-image} }; \draw[red, x={(image.south east)}, y={(image.north west)}] (0.5, 0.5) node (text){\POne00,\si{\micro\meter} }; \end{tikzpicture}

% Switch to old-style numerals: {\LMOldStyle \begin{tikzpicture} \draw (0, 0) node (image){\includegraphics[width=1.1cm]{example-image} }; \draw[red, x={(image.south east)}, y={(image.north west)}] (0.5, 0.5) node (text){100,\si{\micro\meter} }; \end{tikzpicture}}

\end{document}

Mico
  • 506,678
  • "It sounds like you're looking for proportionally spaced, rather than the usual fixed spaced, numerals." - yes, exactly! Unfortunately, pdflatex is what I am using. – bers Nov 07 '20 at 12:13
  • @bers - Is something preventing you from switching to either XeLaTeX or LuaLaTeX? – Mico Nov 07 '20 at 16:59
  • Well, not a priori. But while pdflatex works, lualatex fails ("(pdf inclusion): reading image failed" for a pdf file), and my fear is that this is only the first of several incompatibilities between the two engines that I would need to track down to tighten a single digit. – bers Nov 09 '20 at 06:03
  • @bers - Thanks for this follow-up. You may want to post a new query, to ask why a test document that includes a pdf file (via an \includegraphics directive?) compiles sucessfully under pdfLaTeX but not under LuaLaTeX. – Mico Nov 09 '20 at 06:13
  • fyi, https://tex.stackexchange.com/q/570161/30810. LuaLaTeX compiles the file just fine now. Let's see how different the result is from pdflatex :) – bers Nov 09 '20 at 14:03