我编写了一个宏,\createEnvironment{lemma}{Lemma}
可以自动创建几个具有不同风格且标题应该是的环境lemma
、、、。lemma1
lemma2
lemma3
Lemma
我的问题是标题总是“定理”。
例如,
\begin{lemma}
Test
\end{lemma}
\begin{lemma2}
Test
\end{lemma2}
将输出
为什么会这样?如何解决?
平均能量损失
以下 MWE 确实创建了不同的风格,但所有环境的标题始终是“定理”。
\documentclass{article}
\usepackage{ntheorem}
\usepackage{tcolorbox}
\theoremstyle{break}
% Style
\newcommand{\putFrameForEnvironment}[2]
{\tcolorboxenvironment{#1}{ colback = white,
colframe = black,
boxrule = 0pt,
leftrule = #2,
left = 3mm,
right = 0mm,
top = 0mm,
bottom = 0mm,
arc = 0pt,
outer arc = 0pt,
left skip = 5mm-#2,
before = {\vspace{3pt}},
oversize
}}
\newcommand{\createEnvironment}[2]
{
\def\zerothName{#1}%
\def\firstName{#11}%
\def\secondName{#12}%
\def\thirdName{#13}%
\newtheorem*{\zerothName}{#2}
\newtheorem*{\firstName}{#2}
\newtheorem*{\secondName}{#2}
\newtheorem*{\thirdName}{#2}
\putFrameForEnvironment{\zerothName}{0mm}
\putFrameForEnvironment{\firstName}{1mm}
\putFrameForEnvironment{\secondName}{2mm}
\putFrameForEnvironment{\thirdName}{3mm}
}
\createEnvironment{lemma}{Lemma}
\createEnvironment{proposition}{Proposition}
\createEnvironment{theoreme}{Theorem}
\begin{document}
\begin{lemma}
Test
\end{lemma}
\begin{lemma2}
Test
\end{lemma2}
\end{document}
答案1
与之不同amsthm
,ntheorem
对\newtheorem
或 的第一个参数不进行扩展\newtheorem*
。
如果我要求\show\lemma
,我得到
> \lemma=macro:
->\let \thm@starredenv \@undefined \csname mkheader@\zerothName \endcsname .
然后你就会看到问题:你没有lemma
,但是\zerothName
。它具有最后设置的值。
我认为没有必要使用\zerothName
等等。但你可以切换到amsthm
。
这是一个我做过修复的版本:您应该使用before skip=10pt
,而不是before={\vspace{10pt}}
。
\documentclass{article}
\usepackage{ntheorem}
%\usepackage{amsthm}
\usepackage{tcolorbox}
% if you want to change to amsthm
% \newtheoremstyle{break}%
% {}{}%
% {\itshape}{}%
% {\bfseries}{}% % Note that final punctuation is omitted.
% {\newline}{}
\theoremstyle{break}
% Style
\newcommand{\putFrameForEnvironment}[2]{%
\tcolorboxenvironment{#1}{
colback = gray!20,% white,% just to see better
colframe = black,
boxrule = 0pt,
leftrule = #2,
left = 3mm,
right = 0mm,
top = 0mm,
bottom = 0mm,
arc = 0pt,
outer arc = 0pt,
left skip = 5mm-#2,
before skip = 10pt, % <------- not "before={\vspace{10pt}}"
oversize,
}%
}
\newcommand{\createEnvironment}[2]{%
\def\zerothName{#1}%
\def\firstName{#11}%
\def\secondName{#12}%
\def\thirdName{#13}%
\newtheorem*{#1}{#2}%
\newtheorem*{#11}{#2}%
\newtheorem*{#12}{#2}%
\newtheorem*{#13}{#2}%
\putFrameForEnvironment{#1}{0mm}%
\putFrameForEnvironment{#11}{1mm}%
\putFrameForEnvironment{#12}{2mm}%
\putFrameForEnvironment{#13}{3mm}%
}
\createEnvironment{lemma}{Lemma}
\createEnvironment{proposition}{Proposition}
\createEnvironment{theoreme}{Theorem}
\begin{document}
\noindent X\dotfill X
\begin{lemma}
Test
\end{lemma}
\begin{lemma2}
Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test
Test Test Test Test Test Test Test Test
\end{lemma2}
\end{document}
灰色背景只是为了更好地看清位置。
为了进行比较,这是我使用 获得的输出amsthm
。
您可以看到它稍微好一些(查看框的底部)。