![等宽字体(打字机字体)不尊重边距](https://linux22.com/image/463249/%E7%AD%89%E5%AE%BD%E5%AD%97%E4%BD%93%EF%BC%88%E6%89%93%E5%AD%97%E6%9C%BA%E5%AD%97%E4%BD%93%EF%BC%89%E4%B8%8D%E5%B0%8A%E9%87%8D%E8%BE%B9%E8%B7%9D.png)
我尝试在文档中使用打字机字体 (TXTT),但它总是超出边距。我不知道这是正常的还是我的文档出了错。
下面是一个 MWE:
\documentclass[a4paper, 12pt]{memoir}
% Load packages
\usepackage[showframe]{geometry}
\usepackage[colorlinks = true, urlcolor = blue, linkcolor = black]{hyperref}
\usepackage{enumitem}
\setlist{itemsep=0.05em}
\usepackage{xfrac}
\usepackage{booktabs}
\usepackage{tocloft}
\usepackage{lipsum}
% TXTT typewriter font
\renewcommand*\ttdefault{txtt}
\renewcommand*\familydefault{\ttdefault} %% Only if the base font of the document is to be typewriter style
\usepackage[T1]{fontenc}
% Formatting matters
\setlength\parskip{1em}
\setlength\parindent{0em}
\renewcommand\contentsname{} % the empty ToC name
\renewcommand{\labelitemii}{$\circ$}
% =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
\begin{document}
\lipsum
\end{document}
答案1
您可以自行加载字体定义文件,并将其修改为
- 允许连字符,因此删除
\hyphenchar\font=\m@ne
; - 为每种字体定义一个可拉伸性;
- 为每种字体定义一个可收缩性。
\documentclass[a4paper, 12pt]{memoir}
% Load packages
\usepackage[T1]{fontenc}
\usepackage{kantlipsum}
% TXTT font
\newcommand{\fixfontdimens}{%
\fontdimen3\font=0.5\fontdimen2\font
\fontdimen4\font=0.2\fontdimen2\font
}
\DeclareFontFamily{T1}{txtt}{}
\DeclareFontShape{T1}{txtt}{m}{n}{<->t1xtt}{\fixfontdimens}
\DeclareFontShape{T1}{txtt}{m}{sc}{<->t1xttsc}{\fixfontdimens}
\DeclareFontShape{T1}{txtt}{m}{sl}{<->t1xttsl}{\fixfontdimens}
\DeclareFontShape{T1}{txtt}{m}{it}{<->ssub * txtt/m/sl}{}
\DeclareFontShape{T1}{txtt}{m}{ui}{<->ssub * txtt/m/sl}{}
\DeclareFontShape{T1}{txtt}{bx}{n}{<->t1xbtt}{\fixfontdimens}
\DeclareFontShape{T1}{txtt}{bx}{sc}{<->t1xbttsc}{\fixfontdimens}
\DeclareFontShape{T1}{txtt}{bx}{sl}{<->t1xbttsl}{\fixfontdimens}
\DeclareFontShape{T1}{txtt}{bx}{it}{<->ssub * txtt/bx/sl}{}
\DeclareFontShape{T1}{txtt}{bx}{ui}{<->ssub * txtt/bx/sl}{}
\DeclareFontShape{T1}{txtt}{b}{n}{<->ssub * txtt/bx/n}{}
\DeclareFontShape{T1}{txtt}{b}{sc}{<->ssub * txtt/bx/sc}{}
\DeclareFontShape{T1}{txtt}{b}{sl}{<->ssub * txtt/bx/sl}{}
\DeclareFontShape{T1}{txtt}{b}{it}{<->ssub * txtt/bx/it}{}
\DeclareFontShape{T1}{txtt}{b}{ui}{<->ssub * txtt/bx/ui}{}
\renewcommand*\ttdefault{txtt}
\renewcommand*\familydefault{\ttdefault}
\begin{document}
\kant[1]
\textit{\kant[1][1-3]}
\textbf{\kant[1][4-6]}
\end{document}