带星号的 ntheorem 标题中出现换行符

带星号的 ntheorem 标题中出现换行符

我碰到这个问题之前发布过,并且已经使用了一段时间。但是,我似乎无法让同样的东西在星号环境中工作。

我知道定理标题过长一直是 的一个长期缺陷ntheorem。但是,如果存在这样的解决方法,我将非常感激您能提供一些关于如何解决这个问题的提示。

以下是使用 tufte 类的 MWE,只是为了与我通常的设置保持一致。

\documentclass{tufte-book}
\usepackage{etoolbox}
\usepackage{ntheorem}

% Workaround for long titles in ntheorem
\makeatletter
\let\nobreakitem\item
\let\@nobreakitem\@item
\patchcmd{\nobreakitem}{\@item}{\@nobreakitem}{}{}
\patchcmd{\nobreakitem}{\@item}{\@nobreakitem}{}{}
\patchcmd{\@nobreakitem}{\@itempenalty}{\@M}{}{}
\patchcmd{\@xthm}{\ignorespaces}{\nobreak\ignorespaces}{}{}
\patchcmd{\@ythm}{\ignorespaces}{\nobreak\ignorespaces}{}{}

\renewtheoremstyle{break}%
  {\item{\theorem@headerfont
          ##1\ ##2\theorem@separator}\hskip\labelsep\relax\nobreakitem}%
  {\item{\theorem@headerfont
          ##1\ ##2\ (##3)\theorem@separator}\hskip\labelsep\relax\nobreakitem}
\makeatother

\theoremstyle{break}
\theoremprework{\textcolor{magenta}{\hrule height 2pt width \textwidth}}
\theoremheaderfont{\color{magenta}\normalfont\bfseries}
\theorempostwork{\textcolor{magenta}{\hrule height 2pt width \textwidth}}
\theoremindent10pt
\newtheorem{theorem}{Theorem}

\theoremprework{\textcolor{magenta}{\hrule height 2pt width \textwidth}}
\theoremheaderfont{\color{magenta}\normalfont\bfseries}
\theorempostwork{\textcolor{magenta}{\hrule height 2pt width \textwidth}}
\theoremindent10pt
\newtheorem*{theoremn}{Theorem}

\begin{document}
\begin{theorem}[Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem]
  This is a numbered theorem.
\end{theorem}

\begin{theoremn}[Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem]
  This is an unnumbered theorem.
\end{theoremn}
\end{document}

下面是其外观的图像: 编号定理与非编号定理

对于那些打算推荐 的人amsthm,请注意,我无法实现使用 可以实现的定理环境的样式ntheorem,这就是为什么我宁愿用ntheorem而不是放弃它来找到解决方案。此外,使用框架(例如mdframed)是行不通的,因为我也在使用 tufte 类,而且我非常依赖文档中有足够的旁注和边注。

答案1

你可以加

\def\thm@nonumberbreak{%
  \def\@begintheorem##1##2{%
    \item
    {\theorem@headerfont##1\theorem@separator}
    \hskip\labelsep\relax\nobreakitem 
  }%
  \def\@opargbegintheorem##1##2##3{%
    \item 
    {\theorem@headerfont##1\ (##3)\theorem@separator}%
    \hskip\labelsep\relax\nobreakitem 
  }%
}

之前\makeatother。更简单的是,使用regexpatch而不是etoolbox

\documentclass{tufte-book}
\usepackage{regexpatch}
\usepackage{ntheorem}

% Workaround for long titles in ntheorem
\makeatletter
\let\nobreakitem\item
\let\@nobreakitem\@item
\xpatchcmd{\nobreakitem}{\@item}{\@nobreakitem}{}{}
\xpatchcmd{\nobreakitem}{\@item}{\@nobreakitem}{}{}
\xpatchcmd{\@nobreakitem}{\@itempenalty}{\@M}{}{}
\xpatchcmd{\@xthm}{\ignorespaces}{\nobreak\ignorespaces}{}{}
\xpatchcmd{\@ythm}{\ignorespaces}{\nobreak\ignorespaces}{}{}

\renewtheoremstyle{break}%
  {\item{\theorem@headerfont
          ##1\ ##2\theorem@separator}\hskip\labelsep\relax\nobreakitem}%
  {\item{\theorem@headerfont
          ##1\ ##2\ (##3)\theorem@separator}\hskip\labelsep\relax\nobreakitem}
% make \th@nonumberbreak the same as \th@break, but remove "\ ##2"
\let\th@nonumberbreak\th@break
\xpatchcmd*{\th@nonumberbreak}{\ ##2}{}{}{}
\makeatother

\theoremstyle{break}
\theoremprework{\textcolor{magenta}{\hrule height 2pt width \textwidth}}
\theoremheaderfont{\color{magenta}\normalfont\bfseries}
\theorempostwork{\textcolor{magenta}{\hrule height 2pt width \textwidth}}
\theoremindent10pt
\newtheorem{theorem}{Theorem}

\theoremprework{\textcolor{magenta}{\hrule height 2pt width \textwidth}}
\theoremheaderfont{\color{magenta}\normalfont\bfseries}
\theorempostwork{\textcolor{magenta}{\hrule height 2pt width \textwidth}}
\theoremindent10pt
\newtheorem*{theoremn}{Theorem}

\begin{document}
\begin{theorem}[Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem]
  This is a numbered theorem.
\end{theorem}

\begin{theoremn}[Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem Theorem]
  This is an unnumbered theorem.
\end{theoremn}
\end{document}

在此处输入图片描述

相关内容