自定义定理名称

自定义定理名称

假设我有一系列定理,希望将其显示为

吉姆定理。

鲍勃定理。

威尔定理。

而不是“定理(吉姆)”、“定理(鲍勃)”和“定理(威尔)”。如果我有很多这样的定理,那么总是必须回到序言来定义一个新的定理环境就变得很乏味了。所以我很好奇是否有某种方法来定义一个接受定理标题作为参数的新定理环境。理想情况下,我希望我可以输入一些东西,例如

\begin{namedtheorem}{Jim's Theorem}
...
\end{namedtheorem}

并产生

吉姆定理。...

我可以通过定义一个单独的新环境来实现非常相似的效果,但我无法使其前后的间距与定理环境前后的正常间距相匹配。

感谢您的任何建议。

答案1

您可以使用amsthms 可自定义的 theoremstyles 来执行此操作。诀窍就是弄清楚要传递哪些参数!通过反复试验,我得出了以下结论:

\documentclass{minimal}

\usepackage{amsthm}

\newtheorem*{theorem}{Theorem}

\newtheoremstyle{named}{}{}{\itshape}{}{\bfseries}{.}{.5em}{\thmnote{#3's }#1}
\theoremstyle{named}
\newtheorem*{namedtheorem}{Theorem}


\begin{document}

Now let us present that most famous of all theorems.

\begin{theorem}[Fred]
All odd numbers are prime.
\end{theorem}

If you don't believe that Fred was involved, you may prefer the following.

\begin{theorem}
All odd numbers are prime.
\end{theorem}

The proof of this is left as an exercise.
Of course, some may prefer to see this as follows.

\begin{namedtheorem}[Fred]
All odd numbers are prime.
\end{namedtheorem}

But still, we shan't bother with the proof here.
As we said, some people don't think that Fred had much to do with this.

\begin{namedtheorem}
All odd numbers are prime.
\end{namedtheorem}

Nonetheless, the proof remains trivial.

\end{document}

这是结果。请注意,第一个定理是默认样式,因此它是第二对你应该看看。

命名定理

编辑中添加:我不清楚\thmnote在做什么;进一步的实验表明,如果可选参数不是given 会将\thmnote其参数全部吞掉,因此可以根据参数是否给出来改变行为。如果您忘记了 Fred,这会让它看起来更好。)

答案2

Loop Space 的答案很好,但缺点是破坏了可选参数,因此无法再指定归属。

我建议使用强制参数。

\documentclass{article}
\usepackage{amsthm}

\swapnumbers % optional, of course
\newtheorem{thm}{Theorem}[section] % the main one
\newtheorem{lemma}[thm]{Lemma}
% other statement types

% for specifying a name
\theoremstyle{plain} % just in case the style had changed
\newcommand{\thistheoremname}{}
\newtheorem{genericthm}[thm]{\thistheoremname}
\newenvironment{namedthm}[1]
  {\renewcommand{\thistheoremname}{#1}%
   \begin{genericthm}}
  {\end{genericthm}}

\begin{document}

\section{Something}

A theorem

\begin{thm}
$1+1=2$.
\end{thm}

And a named theorem

\begin{namedthm}{Zorn's Lemma}[Zermelo]
All well-behaved ordered sets have maximal elements.
\end{namedthm}

\end{document}

在此处输入图片描述

当然,强制参数后面的可选参数\begin{namedthm}确实是可选的。

对于未编号的定理,genericthm*以相同的方式定义定理

\newtheorem*{genericthm*}{\thistheoremname}
\newenvironment{namedthm*}[1]
  {\renewcommand{\thistheoremname}{#1}%
   \begin{genericthm*}}
  {\end{genericthm*}}

\begin{namedthm*}{Zorn's Lemma}

或者

\begin{namedthm*}{Zorn's Lemma}[Zermelo]

会做。

答案3

ntheorem 包更加灵活

\documentclass[a4paper]{memoir}
\usepackage{amsmath}
\usepackage[amsmath,thmmarks]{ntheorem}
% normal theorem
\theoremseparator{.}
\newtheorem{theorem}{Theorem}
% Now the optional argument takes over
\theoremstyle{empty}
\newtheorem{namedtheorem}{}
\begin{document}

\begin{theorem}
 Some text
\end{theorem}

\begin{namedtheorem}[Jim's Theorem.]
  Extra text
\end{namedtheorem}
\end{document}

答案4

亨德里克对John Palmieri 的回答在这个页面的某个地方(或者可能是上一个或下一个,如果这个问题有足够多的答案:))

\documentclass{article}
\usepackage{amsthm}

\newcounter{nmdthmcnt}
\newenvironment{namedthm}[2][]{\addtocounter{nmdthmcnt}{1}%
    \theoremstyle{plain}\newtheorem*{nmdthm\roman{nmdthmcnt}}{#2's Theorem}%
    \begin{nmdthm\roman{nmdthmcnt}}[#1]}{\end{nmdthm\roman{nmdthmcnt}}}

\begin{document}

Test. This is

\begin{namedthm}{Willie}
A theorem that I just proved recently
\end{namedthm}

here's another

\begin{namedthm}{Some big-shot dude}
A theorem that I am just borrowing
\end{namedthm}

And my theorem again,

\begin{namedthm}[version 2]{Willie}
Restatement of the theorem.
\end{namedthm}
\end{document}

我为每个定理环境使用一个计数器,而不仅仅是贡献者的“名称”,这样名称中的空格和特殊字符就不会破坏命令\newtheorem,而且我不必担心名称冲突。我还包含了与定理可选参数的兼容性,如您在第三个示例中所见。

相关内容