我正在使用 ntheorem 来定义我自己的环境,如下所示
\theoremindent=0cm
\theoremheaderfont{\kern-0cm\normalfont\bfseries}
\theorembodyfont{\upshape}
\theoremstyle{break}
\newtheorem{problem}{Problem}
\begin{problem}[Very very very very very very very very very very very very long name]
foo
\end{problem}
问题是名称太长,一行无法容纳,但没有调用换行符。
我该如何改变这种情况?我发现如何在定理标题中换行?但答案不是针对包 ntheorem 的。
答案1
使用阿姆斯特丹可以避免这种问题,所以除非你真的需要 ntheorem 的某个功能,否则我建议切换。
否则,您可以修改 ntheorem 的换行样式以允许换行,但这种新样式在某些情况下不会以相同的方式工作(但应该足够相似而不会造成困扰):
\documentclass{article}
\usepackage{ntheorem}
\usepackage{etoolbox}% for command patching
\usepackage{lipsum}% for dummy text
\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
\theoremindent=0cm
\theoremheaderfont{\kern-0cm\normalfont\bfseries}
\theorembodyfont{\upshape}
\theoremstyle{break}
\newtheorem{problem}{Problem}
\begin{document}
\begin{problem}[Very very very very very very very very very very very very long name]
\lipsum[1]
\end{problem}
\begin{problem}
\lipsum[1]
\end{problem}
\begin{problem}
\begin{enumerate}
\item Foo
\item Bar
\end{enumerate}
\end{problem}
\vspace{4cm}
\begin{problem}
\lipsum[1]
\end{problem}
\end{document}