使用 \newtheoremstyle 定义自定义示例环境

使用 \newtheoremstyle 定义自定义示例环境

我正在尝试为我的论文定义一个自定义示例环境,但由于我对 LaTeX 的了解有限,我无法从中弄清楚这一点amsthm文档。这是一个最小工作示例,或者更准确地说,是一个我希望它看起来像的工作示例。

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage{amsthm}
\newtheoremstyle{example} ... % something to add that makes sense

\begin{document}

\chapter{First Chapter}
\blindtext

\begin{example}
Here is an example with with some random text that covers multiple lines such that we have a good visual understanding of the lay-out. The example must cover about three lines.
\end{example}

\blindtext

\begin{example}
Here is another example with with some random text that covers multiple lines such that we have a good visual understanding of the lay-out. The example must cover about three lines.
\end{example}

And some text at the end of the chapter.

\end{document}

然后我想要的输出应该是这样的:

在此处输入图片描述

我尝试\newtheoremstyle{break}按照第 9 页文档中描述的方式使用amsthm,但没有成功。最好我还想能够设置示例上方和下方的空间,以便清楚地知道示例在布局中的间距停止的位置。我希望这不是一个愚蠢的问题,但我自己从文档中根本无法弄清楚。

最好的,科恩

答案1

使用 很容易做到ntheorem。我给包加载了选项thref(定理类环境的扩展引用)和thmmarks(自动放置证明结束符号,包括当证明以方程式结尾时):

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath} %
\usepackage{blindtext}

\usepackage[thref, thmmarks, amsmath]{ntheorem}
\theoremstyle{break}
\theoremheaderfont{\bfseries}
\theorembodyfont{\normalfont}
\theoremseparator{\medskip}
\theorempreskip{\bigskipamount}
\newtheorem{example}{Example}[chapter]

\begin{document}

\chapter{First Chapter}

\blindtext

\begin{example}
  Here is an example with with some random text that covers multiple lines such that we have a good visual understanding of the lay-out. The example must cover about three lines.
\end{example}

\blindtext

\begin{example}
  Here is another example with with some random text that covers multiple lines such that we have a good visual understanding of the lay-out. The example must cover about three lines.
\end{example}

And some text at the end of the chapter.

\end{document}

在此处输入图片描述

答案2

Bernard 的回答很好,但如果你想坚持使用该amsthm软件包,那么你也可以执行以下操作,正如我后来发现的那样。

    \documentclass{book}
    \usepackage[utf8]{inputenc}
    \usepackage[english]{babel}
    \usepackage{amsmath} %
    \usepackage{blindtext}

    \newtheoremstyle{break}%
    {2em}{2em}%
    {}{}%
    {\bfseries}{}% % Note that final punctuation is omitted.
    {\newline}{}

    \theoremstyle{break}
    \newtheorem{example}{Example}[chapter]

    \begin{document}

    \chapter{First Chapter}

    \blindtext

    \begin{example}
      Here is an example with with some random text that covers multiple lines such that we have a good visual understanding of the lay-out. The example must cover about three lines.
    \end{example}

    \blindtext

    \begin{example}
      Here is another example with with some random text that covers multiple lines such that we have a good visual understanding of the lay-out. The example must cover about three lines.
    \end{example}

    And some text at the end of the chapter.

    \end{document}

这给出了非常相似的输出,并且通过其中{2em}{2em}的部分\newtheoremstyle{break},我能够手动选择新环境上方和下方的空格。

相关内容