Why is there extra space after (:) in \texttt{}

This is the affect of the default \nonfrenchspacing which adds extra space after sentence/clause ending punctuation. The monospacing of \texttt highlights the effect.

\texttt{\frenchspacing1234 : 8901}\\

produces even spacing as does

\verb|1234 : 8901|\\

The space after the colon is bigger also in \textsf, but much less than in \texttt. If I try

\sbox0{\textsf{1234 : 8901}}\showthe\wd0
\sbox0{\frenchspacing\textsf{1234 : 8901}}\showthe\wd0

I get

> 59.40216pt.
l.28 \sbox0{\textsf{1234 : 8901}}\showthe\wd0

?
> 58.09662pt.
l.29 ...chspacing\textsf{1234 : 8901}}\showthe\wd0

so an extra 1.3pt is added without frenchspacing. The abnormal spacing in \texttt is due to the font spacing parameters; these are those for cmtt10

(FONTDIMEN
   (SLANT R 0.0)
   (SPACE R 0.524996)
   (STRETCH R 0.0)
   (SHRINK R 0.0)
   (XHEIGHT R 0.430555)
   (QUAD R 1.049991)
   (EXTRASPACE R 0.524996)
   )

while cmss10 has

(FONTDIMEN
   (SLANT R 0.0)
   (SPACE R 0.333334)
   (STRETCH R 0.166667)
   (SHRINK R 0.111112)
   (XHEIGHT R 0.444445)
   (QUAD R 1.000003)
   (EXTRASPACE R 0.111112)
   )

and EXTRASPACE is the culprit here, together with the space factor code associated to the colon, which is 2000.

Now, \ttfamily can be used for emulating a typewriter and space factor works like typists were used to do (at least in the US), leaving additional space after sentence ending periods and colons.

You can redefine \ttfamily to be "non space extending" by adding the following code to your preamble

\makeatletter
\let\ttfamily\relax % avoid a spurious warning
\DeclareRobustCommand\ttfamily
        {\not@math@alphabet\ttfamily\mathtt
         \fontfamily\ttdefault\selectfont\frenchspacing}
\makeatother

The command \texttt uses internally the current definition of \ttfamily, so you don't need to redefine it.

This is simply the kernel definition of \ttfamily, with \frenchspacing added. More simply,

\usepackage{xpatch}
\xapptocmd{\ttfamily}{\frenchspacing}{}{}

Tags:

Spacing