例では \ttfamily フォントを体系的に使用します

例では \ttfamily フォントを体系的に使用します

私の問題はタイトルの通りです: \ttfamilyフォントを使いたい体系的に例のみで、\documentclass{amsbook} 内にあります。このようにするのは、例を周囲のテキストと区別するためです。

理想的な方法は次のようになります\newtheorem{example}[thm]{Example}[\ttfamily](残念ながら機能しません)。

答え1

簡単で手っ取り早い方法は、新しい定理スタイル ( \newtheoremstyle) を定義するための「公式」コマンドをバイパスし、フォント設定のみを含む内部コマンドを使用してスタイルを定義することです。これは、たとえばのソースで\th@somestyle組み込みスタイルが定義される方法に似ています。definitionamsthm

テレタイプは通常、文字幅が固定されているため、行は不揃いになることが多いです。両端揃えのテキストが必要な場合は、フォントサイズを変更することができます。http://texblog.net/latex-archive/plaintex/full-justification-with-typewriter-font/

MWE:

\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}

結果:

ここに画像の説明を入力してください

関連情報