在 amsthm 包中,计数器也应该用斜体表示

在 amsthm 包中,计数器也应该用斜体表示

在我的文档中,我需要用斜体表示一些定理标题,用粗体表示一些定理标题,我使用以下标签:

\documentclass{book}
\usepackage{amsthm}
\newtheoremstyle{note}% name
{3pt}% Space above1
{3pt}% Space below1
{}% Body font
{}% Indent amount2
{\itshape}% Theorem head font
{:}% Punctuation after theorem head
{.5em}% Space after theorem head3
{}%
\theoremstyle{note}
\newtheorem{test}{Test}

\newtheoremstyle{bfnote}% name
{3pt}% Space above1
{3pt}% Space below1
{}% Body font
{}% Indent amount2
{\bf}% Theorem head font
{:}% Punctuation after theorem head
{.5em}% Space after theorem head3
{}%
\theoremstyle{bfnote}
\newtheorem{trial}{Trial}
\begin{document}


\begin{test}
This is for test.
\end{test}


\begin{trial}
This is for test.
\end{trial}


\end{document}

对于粗体,计数器也以粗体显示;对于斜体,计数器以罗马字体显示,但我还需要斜体格式的计数器。我该如何实现?

答案1

您需要使用最后一个参数\newtheoremstyle(参见文档第 4.3 节amsthm

\newtheoremstyle{note}% name
{3pt}% Space above1
{3pt}% Space below1
{}% Body font
{}% Indent amount2
{\itshape}% Theorem head font
{:}% Punctuation after theorem head
{.5em}% Space after theorem head3
{\thmname{#1}\thmnumber{ #2}}% THEOREM HEAD SPEC (IF EMPTY MEANS `NORMAL')
\theoremstyle{note}
\newtheorem{test}{Test}

在此处输入图片描述

顺便说一下,在你的第二个例子(bfnote)中你最好\bf 用替换\bfseries

编辑我很困惑为什么原来的方法不起作用,于是我研究了的代码。如果没有提供amsthm第九个参数,定理头默认为,其定义为\newtheoremstyle\thmhead@plain

\providecommand\@upn{\textup}
\def\thmhead@plain#1#2#3{%
  \thmname{#1}\thmnumber{\@ifnotempty{#1}{ }\@upn{#2}}%
  \thmnote{ {\the\thm@notefont(#3)}}}

因此,无论定理头字体如何(第六个参数),的存在\@upn都会迫使计数器保持直立。

编辑2更好的方法是保留完整的原始定义,\thmhead@plain但以下位除外\@upn

\makeatletter
\newtheoremstyle{note}% name
{3pt}% Space above1
{3pt}% Space below1
{}% Body font
{}% Indent amount2
{\itshape}% Theorem head font
{:}% Punctuation after theorem head
{.5em}% Space after theorem head3
{\thmname{#1}\thmnumber{\@ifnotempty{#1}{ }#2}%
 \thmnote{ {\the\thm@notefont(#3)}}}% theorem head
\makeatother

如果使用可选参数调用该定理,则原始答案将会失败。

相关内容