在範例中系統地使用 \ttfamily 字體

在範例中系統地使用 \ttfamily 字體

我的問題如標題所示:我想使用 \ttfamily 字體僅有系統地舉例,在 \documentclass{amsbook} 內。我這樣做是因為我想以這種方式將範例與周圍的文字區分開來。

理想的方法應該是類似的\newtheorem{example}[thm]{Example}[\ttfamily](不幸的是,這不起作用)。

答案1

一種快速簡單的方法是繞過用於定義新定理樣式(即 )的「官方」命令,並使用僅具有字體設定的\newtheoremstyle內部命令來定義樣式。\th@somestyle這類似於definition在 的源代碼中定義內建樣式的方式amsthm

電傳打字機通常具有固定寬度的字符,因此線條通常不均勻。如果您想要對齊文本,您可以修改一些字體尺寸,請參閱http://texblog.net/latex-archive/plaintex/full-justification-with-typewriter-font/

微量元素:

\documentclass{amsbook}
\usepackage{amsthm}
\makeatletter
\def\th@example{%
  \ttfamily % body font
  \fontdimen2\font=0.4em% interword space
  \fontdimen3\font=0.2em% interword stretch
  \fontdimen4\font=0.1em% interword shrink
  \fontdimen7\font=0.1em% extra space
}
\makeatother
\newtheorem{thm}{Theorem}
\theoremstyle{example}
\newtheorem{example}[thm]{Example}

\begin{document}
This is an example:
\begin{example}
An example can be short, or long, such as an entire line this is repeated a few times.
An example can be short, or long, such as an entire line this is repeated a few times.
An example can be short, or long, such as an entire line this is repeated a few times.
\end{example}
This is a theorem:
\begin{thm}
P is either short or long.
A theorem can be long, such as an entire line this is repeated a few times.
A theorem can be long, such as an entire line this is repeated a few times.
A theorem can be long, such as an entire line this is repeated a few times.
\end{thm}
\end{document}

結果:

在此輸入影像描述

相關內容