在示例中系统地使用 \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/

梅威瑟:

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

结果:

在此处输入图片描述

相关内容