如何創建自訂環境?

如何創建自訂環境?

我想寫下一些定理,如下:

\begin{theorem}
    \begin{preconditions}
        $A := \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$\\
        $B := \begin{pmatrix} 2 & 2 \\ 3 & 4 \end{pmatrix}$\\
        $n \in \mathbb{N}$
    \end{preconditions}

    \begin{claim}
        $\sqrt{2} \notin \mathbb{Q}$
    \end{claim}

    \begin{proof}{directly}
        [... the proof ...]
    \end{proof}

\end{theorem}

它應該看起來像這樣:

**Theorem 123**
    **Preconditions**:
        $A := \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$\\
        $B := \begin{pmatrix} 2 & 2 \\ 3 & 4 \end{pmatrix}$\\
        $n \in \mathbb{N}$

    **Claim**: √2 ∉ Q

    **Proof**: directly

        [... the proof ...]
        [.. the end]                 ■

Theorem 123PreconditionsClaimProof應為粗體)

環境背後的邏輯:

  • 定理應該會自動獲得從 1 開始的數字,並且對於每個定理加一
  • 在定理環境內部,僅允許preconditions,claim和環境proof
  • 在定理環境內部,claimproof環境需要恰好一次。
  • 證明的內容和前提條件的內容應具有相同的意圖。

到目前為止我發現了什麼:

我想\新環境可能是我正在尋找的:

\newenvironment{name}[num]{before}{after}

但我不知道如何根據需要標記內部環境。


amsthm 包似乎有證明環境(來源),但我看不到嵌套不同環境並使它們看起來像我希望它們看起來的可能性


定理似乎提供了很多可能性。我創造了 4 個新的定理環境:

\newtheorem{theorem}{Theorem}
\newtheorem{preconditions}{Preconditions}
\newtheorem{proof}{Proof}
\newtheorem{claim}{Claim}

我使用了上面的乳膠代碼並獲得了這個: 在此輸入影像描述

這個沒有內部環境的意圖,內部環境被編號,儘管它們不應該被編號,並且沒有墓碑是在最後

答案1

我用的是thmtools封裝作為前端,amsthm以便定義新Proof環境;其他兩個環境是使用創建的\newenvironment。和Proof環境使用來自claimpreconditionadjustwidthchangepage包增加左邊距。當然,您可以根據自己的需求隨意進行必要的調整:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{changepage}
\usepackage[nopar]{lipsum}% just to generate some text

\newlength\Thmindent
\setlength\Thmindent{20pt}

\newenvironment{precondition}
  {\par\medskip\adjustwidth{\Thmindent}{}\normalfont\textbf{Preconditions:}\par\nobreak}
  {\endadjustwidth}
\newenvironment{claim}
  {\par\medskip\adjustwidth{\Thmindent}{}\normalfont\textbf{Claim:}}
  {\endadjustwidth}

\declaretheoremstyle[
  spaceabove=0pt,spacebelow=0pt,
  preheadhook=\adjustwidth{\Thmindent}{},
  prefoothook=\endadjustwidth,
  headpunct=:,
  numbered=no,
  qed=\qedsymbol
]{proof}
\declaretheorem[style=proof]{Proof}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
\lipsum[2]
\begin{precondition}
\begin{itemize}
\item $A := \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$
\item $B := \begin{pmatrix} 2 & 2 \\ 3 & 4 \end{pmatrix}$
\item $n \in \mathbb{N}$
\end{itemize}
\end{precondition}
\begin{claim}
$\sqrt{2}\notin\mathbb{Q}$
\end{claim}
\begin{Proof}
\lipsum[2]
\end{Proof}
\end{theorem}

\end{document}

在此輸入影像描述

相關內容