Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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

share|improve this answer
    
Unfortunately I am also using it followed by a list. There is no way to avoid this ugly space? –  Jana Oct 30 '12 at 13:36
    
@Jana: there is a method, but it's a bit more complicated. I've updated my answer to include it. –  Philippe Goutet Oct 30 '12 at 16:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.