10

I am using ntheorem to define my own environments like this

\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}

The problem is that the name is too long to fit in one line, but no line break is invoked.

How can I change this? I found How can I get a line break in a theorem headline? but the answers are not for the package ntheorem.

Jana
  • 2,254
  • 6
  • 21
  • 32

1 Answers1

11

Using amsthm would avoid yourself this kind of problem, so unless there's a feature of ntheorem you really need, I would suggest the switch.

Otherwise, you can modify the break style of ntheorem to allow line breaks, but this new style will not work the same way in some situations (but should be similar enough for it not to be bothering):

\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}

result of the code