更改 \texttt 的字距調整

更改 \texttt 的字距調整

我嘗試使用與 courier 不同的字體作為等寬字體,但此列表中沒有一個(http://www.ctan.org/topic/font-mono)在我的系統上可用 - 並且當我們在分散式系統中工作時,自訂本地新增不是一個選項。 (建置伺服器、標準等)

所以問題是

  1. 是否有可用的等寬字體,更緊湊,即需要更少的水平空間?
  2. 如何減少 \texttt 或整個字體中所有字母的一般字距調整?

答案1

這裡有兩種方法:1)帶有microtype\textls宏,另一種\spaceout是不帶任何套件。我已將這些巨集包裝成\textttA呼叫\textttB形式。

\textls巨集使用可選參數來指定壓縮或擴展,同時使用和\spaceout的值來修改預設間距。\theLetterSpace\extraWordSpace

兩種方法都支援換行。

從下面的評論總結,值得注意的是,該\textls方法支援連字符,而該\spaceout方法不支援。此外, 的參數不能\spaceout包含本身帶有參數的巨集。

\documentclass{article}
\def\theLetterSpace{-0.5pt}
\def\extraWordSpace{-0.5pt}
\newcommand\spaceout[2][\theLetterSpace]{%
  \def\LocalLetterSpace{#1}\expandafter\spaceouthelpA#2 \relax\relax}
\def\spaceouthelpA#1 #2\relax{%
  \spaceouthelpB#1\relax\relax%
  \ifx\relax#2\else\kern\extraWordSpace\ \kern\LocalLetterSpace\spaceouthelpA#2\relax\fi
}
\def\spaceouthelpB#1#2\relax{%
  #1%
  \ifx\relax#2\else
    \kern\LocalLetterSpace\spaceouthelpB#2\relax%
  \fi
}
\parskip 1ex
\usepackage{microtype}
\def\textttA#1{\texttt{\textls*[-70]{#1}}}
\def\textttB#1{\texttt{\spaceout{#1}}}
\begin{document}
\def\mytext{a bit of texttt}
This is \texttt{\mytext}\par
This is \textttA{\mytext}\par
This is \textttB{\mytext}\par
\def\mytext{a bit of texttt. a bit of texttt. a bit of texttt. a bit of texttt. 
a bit of texttt. a bit of texttt. a bit of texttt. a bit of texttt. }
\noindent\hrulefill\sloppy\par
This is \texttt{\mytext}\par
This is \textttA{\mytext}\par
This is \textttB{\mytext}
\end{document}

在此輸入影像描述

在此輸入影像描述

相關內容