使用 amsthm 进行完整缩进的 theoremstyle

使用 amsthm 进行完整缩进的 theoremstyle

我想使用 amsthm 定义一个定理样式,以便用\newtheorem这种样式生成的完整环境内容可以缩进。

以下独立示例使用了带有悬挂缩进的定理环境

\documentclass{article}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[english]{babel}
\usepackage{blindtext}
\newtheoremstyle{indented}{3pt}{3pt}{\addtolength{\leftskip}{2.5em}}{}{\bfseries}{.}{.5em}{}

\theoremstyle{indented}
\newtheorem{definition}{Definition}

\begin{document}
  \blindtext
  \begin{definition}[test]
    some text
    \begin{enumerate}
      \item an item
      \item another item
    \end{enumerate}
    more text.
  \end{definition}
  \blindtext
\end{document}

这将产生如下结果: 结果

当然,现在的问题是如何实现缩进,以便列表也能缩进。例如,将整个环境格式化为列表是否可取?如果可取,该怎么做?

我希望保持定义尽可能简单,例如不重新定义 amsthm 命令。

答案1

\@totalleftmargin通过修改(控制嵌套列表缩进)以及\linewidth发出\parshape以考虑这些更改,可以使您的代码正常工作:

代码结果

\documentclass{article}
%\documentclass[fleqn]{article}

\usepackage{amsthm}

\newcommand{\Blabla}{Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla.}

\makeatletter
\newtheoremstyle{indented}
  {3pt}% space before
  {3pt}% space after
  {\addtolength{\@totalleftmargin}{3.5em}
   \addtolength{\linewidth}{-3.5em}
   \parshape 1 3.5em \linewidth}% body font
  {}% indent
  {\bfseries}% header font
  {.}% punctuation
  {.5em}% after theorem header
  {}% header specification (empty for default)
\makeatother

\theoremstyle{indented}
\newtheorem{definition}{Definition}

\begin{document}

\Blabla
\begin{definition}
\Blabla
\begin{enumerate}
  \item \Blabla
  \item \Blabla
\end{enumerate}
\Blabla
\[A=B\]
\Blabla
\end{definition}
\Blabla

\end{document}

答案2

我觉得全部类似定理的环境应该以相同的方式处理,因此解决方案可以是在定义中使用list而不是trivlist,从而可以使用\leftmargin

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@thm}{\trivlist}{\list{}{\leftmargin=2.5em}}{}{}
\patchcmd{\@endtheorem}{\endtrivlist}{\endlist}{}{}
\makeatother

现在诸如此类的声明

\newtheoremstyle{indentedupright}
  {3pt}
  {3pt}
  {} 
  {}
  {\bfseries}
  {.}
  {.5em}
  {}

定义和

\newtheoremstyle{indenteditalic}
  {3pt}
  {3pt}
  {\itshape} 
  {}
  {\bfseries}
  {.}
  {.5em}
  {}

因为定理就够了。


这是一个扩展版本,允许对各种类似定理的环境使用不同的缩进:

\documentclass{amsbook}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@thm}{\trivlist}{\list{}{\leftmargin=\thm@margin}}{}{}
\patchcmd{\@endtheorem}{\endtrivlist}{\endlist}{}{}
\newlength{\thm@margin}
\newcommand{\xnewtheorem}[2][0pt]{%
  \newenvironment{#2}{\thm@margin=#1 \begin{#2INNER}}{\end{#2INNER}}%
  \newtheorem{#2INNER}%
}

\makeatother

\newtheoremstyle{indentedupright}
  {3pt}
  {3pt}
  {} 
  {}
  {\bfseries}
  {.}
  {.5em}
  {}
\newtheoremstyle{indenteditalic}
  {3pt}
  {3pt}
  {\itshape} 
  {}
  {\bfseries}
  {.}
  {.5em}
  {}

\theoremstyle{indenteditalic}
\xnewtheorem{theorem}{Theorem}

\theoremstyle{indentedupright}
\xnewtheorem[2.5em]{definition}{Definition}

\begin{document}
\blindtext
\begin{definition}[Companion and cut-off event]
\label{def:cutoff}
Let $\beta$ be a branching process and let $\prec$ be an adequate partial order on the 
configurations of $\beta$. An event $e$ is a \emph{cut-off event} (with respect to $\prec$) 
if $\beta$ contains a local configuration $[e']$ such that
\begin{enumerate}
\item $Mark(e) = Mark(e')$, and \label{def:cutoff-markequal}
\item $[e'] \prec [e]$ \label{def:cutoff-smaller}
\end{enumerate}
Another way to express the condition \ref{def:cutoff-markequal} is $e' \in [e]_{Mark}$. The 
event $e'$ is called \emph{companion} of $e$, if in addition it is minimal in $[e]_{Mark}$ 
with respect to $\prec$. Moreover, if $\prec$ is total, then the companion of a cut-off 
event $e$ is uniquely defined and is denoted by $e_{\mathfrak{c}}$.
\end{definition}
\blindtext
\begin{theorem}
This is the statement of an important theorem; however we don't want to have an indentation 
for this kind of statement.
\end{theorem}
\end{document}

请注意,如果一个新定理必须与另一个定理共享一个计数器,则语法应该是这样的

\xnewtheorem{prop}[theoremINNER]{Proposition}

(带或不带缩进的可选参数)。


用于指定左边距和右边距的变体;在这种情况下,长度是强制参数;可以添加键值接口。

\documentclass{amsbook}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[english]{babel}
\usepackage{etoolbox}

\usepackage{lipsum}


\makeatletter
\patchcmd{\@thm}
  {\trivlist}
  {\list{}{\leftmargin=\thm@leftmargin\rightmargin=\thm@rightmargin}}
  {}{}
\patchcmd{\@endtheorem}
  {\endtrivlist}
  {\endlist}
  {}{}
\newlength{\thm@leftmargin}
\newlength{\thm@rightmargin}

\newcommand{\xnewtheorem}[3]{%
  \newenvironment{#3}
    {\thm@leftmargin=#1\relax\thm@rightmargin=#2\relax\begin{#3INNER}}
    {\end{#3INNER}}%
  \newtheorem{#3INNER}%
}

\makeatother

\newtheoremstyle{indentedupright}
  {3pt}
  {3pt}
  {} 
  {}
  {\bfseries}
  {.}
  {.5em}
  {}
\newtheoremstyle{indenteditalic}
  {3pt}
  {3pt}
  {\itshape} 
  {}
  {\bfseries}
  {.}
  {.5em}
  {}

\theoremstyle{indenteditalic}
\xnewtheorem{0pt}{0pt}{theorem}{Theorem}

\theoremstyle{indentedupright}
\xnewtheorem{2.5em}{0pt}{definition}{Definition}
\xnewtheorem{2.5em}{2.5em}{example}{Example}

\begin{document}
\lipsum[2]

\begin{definition}[Companion and cut-off event]\label{def:cutoff}
Let $\beta$ be a branching process and let $\prec$ be an adequate partial order on the 
configurations of $\beta$. An event $e$ is a \emph{cut-off event} (with respect to $\prec$) 
if $\beta$ contains a local configuration $[e']$ such that
\begin{enumerate}
\item $Mark(e) = Mark(e')$, and \label{def:cutoff-markequal}
\item $[e'] \prec [e]$ \label{def:cutoff-smaller}
\end{enumerate}
Another way to express the condition \ref{def:cutoff-markequal} is $e' \in [e]_{Mark}$. The 
event $e'$ is called \emph{companion} of $e$, if in addition it is minimal in $[e]_{Mark}$ 
with respect to $\prec$. Moreover, if $\prec$ is total, then the companion of a cut-off 
event $e$ is uniquely defined and is denoted by $e_{\mathfrak{c}}$.
\end{definition}

\lipsum[3]

\begin{theorem}
This is the statement of an important theorem; however we don't want to have an indentation 
for this kind of statement.
\end{theorem}

\lipsum[3]

\begin{example}
\lipsum[4]
\end{example}

\end{document}

在此处输入图片描述

答案3

如何使用changepage带选项的封装adjustwidth如下图所示:

\documentclass{article}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{changepage}
\newtheoremstyle{indented}{3pt}{3pt}{}{}{\bfseries}{.}{.5em}{}
%
\theoremstyle{indented}
\newtheorem{definition}{Definition}

\begin{document}
  \blindtext
  \begin{adjustwidth}{20pt}{20pt}
  \begin{definition}[test]
    some text
    \begin{enumerate}
      \item an item
      \item another item
    \end{enumerate}
    more text.
  \end{definition}
  \end{adjustwidth}
  \blindtext
\end{document}

在此处输入图片描述

请注意,以上内容可以根据您的需要制作成\newcommand\newenvironment

相关内容