ntheorem 与 amsthm 之间的冲突

ntheorem 与 amsthm 之间的冲突

我正在使用etoolboxntheorem包来自定义定理和方程的编号。一切正常,但会出现以下错误:

  • \qedhere命令未知(编辑:根据一些建议,我找到了一些办法,所以\qedhere问题得到了解决
  • 定理标题(可选参数)以粗体显示

作为 MWE,以下代码

\documentclass{book}  
\usepackage{amsmath}  
\usepackage{etoolbox}  
\usepackage[amsmath,amsthm,framed,thmmarks]{ntheorem}  
%  
\renewcommand{\theequation}{\thechapter.\arabic{equation}}  
\setcounter{equation}{0}  
\newcounter{tempcounter}  
\newtheorem{thm}{Theorem}[chapter]  
%  
\BeforeBeginEnvironment{thm}{\setcounter{tempcounter}{\arabic{equation}}}  
\AtBeginEnvironment{thm}  
{\setcounter{thm}{\thetempcounter}\subequations}  
\AtEndEnvironment{thm}{\endsubequations}  
%  
\begin{document}  
\chapter{This is a chapter}  
\begin{equation}\label{Eq:A}  
2+2=4  
\end{equation}  
\begin{thm}[First Theorem]\label{Thm:First}  
\begin{equation}\label{Eq:B}  
1+1=2  
\end{equation}  
\begin{proof}  
If equation \ref{Eq:A} was trivial, equation \ref{Eq:B} in Theorem \ref{Thm:First} is even more \qedhere \\  
trivial.  
\end{proof}  
\end{thm}  
\end{document}

输出结果如下:

上述 MWE 的输出

\qedhere命令未知,因此被忽略。我认为问题是包amsthm中的选项与包之间存在冲突。但是,如果我添加序言,我会收到类似以下错误ntheoremamsthm\usepackage{amsthm}

! LaTeX Error: Command \theoremstyle already defined.

还有很多。

我想解决上面列出的两个问题,或者有替代代码以便:

  • 定理和方程采用相同的编号,每章重新设置
  • 定理环境中的方程按子编号排列,如上面的 MWE 输出所示。

任何其他建议都非常感谢。

答案1

ntheorem\qedhere以不同的方式覆盖。这里有一个您可以详细说明的示例。通过(重新)定义定理样式,可以轻松获得“正常字体属性”。

\documentclass{book}  
\usepackage{amsmath,amssymb}  
\usepackage{etoolbox}  
\usepackage[amsmath,framed,thmmarks]{ntheorem}  
%  
\numberwithin{equation}{chapter}
\newcommand{\qedhere}{\ifmmode\qed\else\hfill\proofSymbol\fi}

\makeatletter
\renewtheoremstyle{plain}
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ {\normalfont(##3)}\theorem@separator]}
\makeatother
\theoremstyle{plain}

\newtheorem{thm}{Theorem}[chapter]

\theoremstyle{nonumberplain}
\theoremheaderfont{\itshape}
\theorembodyfont{\normalfont}
\theoremsymbol{\ensuremath{\square}}
\newtheorem{proof}{Proof}
\qedsymbol{\ensuremath{\square}}

\newcounter{tempcounter}
\BeforeBeginEnvironment{thm}{\setcounter{tempcounter}{\arabic{equation}}}  
\AtBeginEnvironment{thm}  
{\setcounter{thm}{\thetempcounter}\subequations}  
\AtEndEnvironment{thm}{\endsubequations}  
%  
\begin{document}  
\chapter{This is a chapter}  
\begin{equation}\label{Eq:A}  
2+2=4  
\end{equation}  
\begin{thm}[First Theorem]\label{Thm:First}  
\begin{equation}\label{Eq:B}  
1+1=2  
\end{equation}  
\begin{proof}  
If equation \ref{Eq:A} was trivial, equation \ref{Eq:B} in Theorem \ref{Thm:First} is even more
trivial.
\[ 0+0=0 \qedhere\]
\end{proof}  
\end{thm}  

\begin{thm}[Second Theorem]\label{Thm:Second}  
\begin{equation}\label{Eq:C}  
1+1=2  
\end{equation}  
\begin{proof}  
If equation \ref{Eq:A} was trivial, equation \ref{Eq:C} in Theorem \ref{Thm:Second} is even more
trivial.
\end{proof}  
\end{thm}  

Let's see another proof.
\begin{proof}
\begin{itemize}
\item Fact one
\item Fact two
\item Fact three\qedhere
\end{itemize}
\end{proof}

\begin{proof}
Here the proof ends with an \texttt{align*} environment.
\begin{align*}
0&=0+0\\
1&=0+1\qedhere
\end{align*}
\end{proof}

\end{document}

相关内容