首字下沉定理风格

首字下沉定理风格

我想要一个类似定理风格的定义,它会导致定理头的首字母大写。

我根本不打算用这种风格来使用计数器。我完全打算使用其他环境,如命题、定义等,我不想改变它们。我更喜欢只使用;但是,我会使用或来amsthm查看解决方案,看看是否与我使用的其他东西有冲突。ntheoremthmtools

MWE 如下:

\documentclass{article}
\usepackage{amsmath, amsthm}
\usepackage{lettrine}
\usepackage{type1cm} % scalable fonts (needed for 'T' to top-align with 'h')
\usepackage{blindtext} % filler text

% Global formatting for the example underneath.
% Ideally, these get replaced with local variants.
\renewcommand{\LettrineFontHook}{\bfseries} % drop-cap bold
\renewcommand{\LettrineTextFont}{\bfseries} % first word bold
\setlength{\DefaultNindent}{0em} % better spacing around T on second line
\setlength{\DefaultFindent}{0.125em}  % better spacing around T on first line
\LettrineRealHeighttrue % align the top of T with top of h

% AMS
\theoremstyle{definition}
\newtheorem*{thm}{Theorem}

\begin{document}
    \lettrine{T}{heorem.} \blindtext    % what I want it to look like

    \begin{thm}     %
        \blindtext  % what I'd like the syntax to be
    \end{thm}       %
\end{document}

我之所以要限制为,amsthm是因为定理环境周围的空白是完美的。因此,另一种解决方案就是模仿间距。我尝试了以下环境定义

\newenvironment{thm}{%
    \noindent\ignorespaces%
    \renewcommand{\LettrineFontHook}{\bfseries}%
    \renewcommand{\LettrineTextFont}{\bfseries}%
    \lettrine[nindent=0em, findent=0.125em, realheight]{T}{heorem.}%
}{
    \renewcommand{\LettrineFontHook}{\scshape}%
    \renewcommand{\LettrineTextFont}{\scshape}%
    \par\noindent\ignorespacesafterend%
}

但是,这种环境表现出了好坏参半的结果。当正文前面有空格时,空格太小。而当正文开始一个部分时,空格又太大。这种环境之后的空格有时很好,有时不好。我无法解释为什么。

答案1

这是一个使用ntheorem创建这样的定理环境。其间距与amsthm定理环境的间距相同。

定理实际上是列表环境,只有一个项目,其标签是定理的头部。首字下沉定理头部的实现有点困难,因为\lettrine不仅会产生定理头部,还会设置定理前两行的缩进。amsthm和都ntheorem允许您更改此标签的外观,但amsthm不允许您插入任何代码定理头部。

但是,这是可能的。的ntheorem第二个和第三个参数通常采用以下形式,您可以使用第三个参数来根据项目标签中发生的情况更改缩进。ntheorem\newtheoremstyle\item[…\theorem@headerfont…]…

为了实现这一点,我们需要从项目标签外部访问(存储使用的参数的\L@parshape变量),这就是我们全局设置为等于此参数的原因。然后我们可以使用和适当地更改下一个段落的形状。\parshapelettrine\dropitem@ps\everypar\parshape

\documentclass{article}

\usepackage{ntheorem}
\usepackage{lettrine}

\makeatletter %% <- make @ usable in command sequences
%% Create drop-cap theorem head:
\newcommand\dropitem[1]{%
  \item[\hskip\itemsep                    %% <- undo \hskip-\itemsep in dfn. of \item
        \lettthmhead{#1}%                 %% <- print drop-capped theorem head
        \global\let\dropitem@ps\L@parshape]% %% <- store \L@parshape for later
  \expandafter\everypar\expandafter{%     %% <- this is inserted at the start of a par.
    \the\everypar                         %% <- original \everpar (prints thm head)
    \parshape\dropitem@ps\relax           %% <- set parshape for first paragraph
    \everypar{\parshape0\everypar{}}%     %% <- reset for later paragraphs
  }%
  \ignorespaces
}
%% Drop-cap a word:
\def\lettthmhead#1{\@lettthmhead#1\end@lettthmhead} %% <- Peel off the first letter
\def\@lettthmhead#1#2\end@lettthmhead{% %% #1 = first letter, #2 = remainder
  \let\LettrineFontHook\theorem@headerfont
  \let\LettrineTextFont\theorem@headerfont
  \lettrine[nindent=0em, findent=0.125em, realheight,novskip=\maxdimen]{#1}{#2}%
}

%% Declare dropcap theorem style:
\newtheoremstyle{dropcap}
  {\dropitem{##1\ ##2\theorem@separator}}
  {\dropitem{##1\ifundefined{thm@starredenv}{}{\ ##2}\ (##3)\theorem@separator}}
\newtheoremstyle{nonumberdropcap}
  {\dropitem{##1\theorem@separator}}
  {\dropitem{##1\ (##3)\theorem@separator}}

\makeatletter  %% <- revert @

%% Declare theorems:
\theoremstyle{dropcap}
\theorempreskip{\topsep}
\theorempostskip{\topsep}
\theoremseparator{.}
\newtheorem*{thm}{Theorem}
\theorembodyfont{\normalfont}
\theoremheaderfont{\normalfont\scshape}
\newtheorem*{dfn}{Definition}

%% Dummy text
\def\lipsum{Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
            Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.
            Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
            consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.}

\begin{document}

\lipsum

\begin{thm}
    \lipsum \par \lipsum
\end{thm}

\lipsum

\begin{thm}
    \lipsum
\end{thm}

\section{A section}

\begin{dfn}
    \lipsum
\end{dfn}
\begin{thm}
    \lipsum
\end{thm}

\lipsum

\end{document}

amsthm左边是 ↓ 输出,右边是上面代码的输出 ↓ )

输出

请注意,使用\newtheorem而不是\newtheorem*会产生这些环境的编号版本。

左侧的输出是使用

\usepackage{amsthm}
\usepackage{lettrine}

\newtheorem*{thm}{Theorem}
\theoremstyle{definition}
\newtheorem*{dfn}{Definition}

以及相同的文档内容。


附录

顺便说一句,AMS 定理的 (完美) 间距可以用trivlist具有\@topsep=\topsep和的环境来重现\@topsepadd=\topsep。下面的环境在几乎所有情况下thmspacing都会被与定理相同大小的空间所包围(因为这实际上是这些环境的定义方式)。amsthm

\makeatletter
\newenvironment{thmspacing}{%
  \trivlist
  \@topsep=\topsep
  \@topsepadd=\topsep
  \item\ignorespaces
}{%
  \endtrivlist
  \@endpefalse
}
\makeatother

以下环境实际上与上面使用 定义的环境几乎没有区别ntheorem。它不需要除 之外的其他软件包lettrine(但您需要从上面复制\dropitem和的定义\lettthmhead才能使用它)。

\makeatletter
\newenvironment{thm}{%
  \trivlist
  \@topsep=\topsep
  \@topsepadd=\topsep
  \itshape
  \def\theorem@headerfont{\normalfont\bfseries}
  \dropitem{Theorem.}
}{%
  \endtrivlist
  \@endpefalse
}
\makeatother

答案2

我想到了一个可怕的想法:

\newtheoremstyle{dropcap}% name of the style to be used
  {\parsep}% measure of space to leave above the theorem.
  {\topsep}% measure of space to leave below the theorem.
  {}% default font to use in the body of the theorem
  {0pt}% NO indenture of theorem head
  {\bfseries}% name of head font --- DOESN'T MATTER
  {}% NO punctuation between head and body
  {0em}% NO space after theorem head;
  {}

\theoremstyle{dropcap}
\newtheorem*{thmx}{} %NO THEOREM NAME

\newenvironment{thm}{
    \ignorespaces%
    \begin{thmx}%
    \renewcommand{\LettrineFontHook}{\bfseries}%
    \renewcommand{\LettrineTextFont}{\bfseries}%
    \lettrine[nindent=0em, findent=0.125em, realheight]{T}{heorem.}%
}{%
    \end{thmx}%
    \renewcommand{\LettrineFontHook}{\scshape}\renewcommand{\LettrineTextFont}{\scshape}%
    \ignorespacesafterend%
}

我知道这违反了编程的几个最佳实践;但是,98% 的时间里,它都能按照我想要的方式进行排版。我注意到的唯一奇怪之处是,如果环境thm在其参数中收到多个段落,它会将第二个段落渲染为缩进,就好像它试图做与第一个段落相同的事情,但没有“定理头”。当然,如果定理的陈述中只有一行,它看起来会很奇怪,但这不是我遇到的情况。

任何其他答案都会对这个答案有所改进。

相关内容