10

I have a theorem title, which is longer then the page width. How do I get the title in two lines?

\begin{theorem}[this title is to long for one line]
the theorem
\end{theorem}
  • I think that the answer by @mas should be the accepted one. – Ioannis Filippidis Mar 14 '16 at 1:36
7

Can you provide more information on the document class and packages you are using? For example, the following code seems to cope with long titles and descriptions but may not be addressing your problem:

\documentclass{amsart}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}[this theorem has a long title that extends well over a line but is handled without any manual intervention on the author's partand even this description goes over a line]
body of the theorem
\end{theorem}
\end{document}

If you could provide a similar Minimal Working Example that shows your problem this would help others to comment on it more usefully than I have here.

Following on from your comment (and assuming you mean scrbook for the class then using the amsthm package may suffice, e.g.:

\documentclass[11pt,a4paper,twoside ,fleqn,headsepline]{scrbook}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}[this theorem has a long title that extends well over a line but is handled without any manual intervention on the author's part and even this description goes over a line]
Body of the theorem
\end{theorem}
\end{document}
  • thanks for the answer, it seems to be my document class: \documentclass[11pt,a4paper,twoside ,fleqn,headsepline]{scrapbook} but scrbook has the best layout I found – Klaus Aug 18 '11 at 15:17
  • You can have a theorem style in most document classes but you may need to load appropriate math packages to achieve what you want to do, I used amsart because that provides a base math setup and you didn't specify which class and styles you were using. I have added an example in the answer above to show one possible approach for a theorem in the class you've chosen. – mas Aug 18 '11 at 15:27
  • 1
    ah not using \usepackage{amsthm} was the problem, thx – Klaus Aug 18 '11 at 15:43
  • Same here, amsthm was accidentally removed through some refactorings that tried to get compatibility with some of Lamport's proof-related packages. – Ioannis Filippidis Mar 14 '16 at 1:36
  • What about the ieeeconf.cls that conflicts with amsthm? The suggestion by Stefan changes how theorems look (e.g., boldface), and I don't know whether there are other ways that it affects the definition of theorem style in ieeeconf.cls. Is there some alternative? – Ioannis Filippidis Mar 14 '16 at 1:47
4

A solution for LaTeX default theorem environment:

\makeatletter
\renewcommand*{\@opargbegintheorem}[3]{\trivlist
  \item[\hskip \labelsep{\bfseries #1\ #2}] \textbf{(#3)}\ \itshape}
\makeatother

Here the macro \@opargbegintheorem is redefined, which originally contains

  \item[\hskip \labelsep{\bfseries #1\ #2\ (#3)}]\itshape}

so the optional theorem title has been moved to after the label instead if being within, so now line breaks are possible.

Test example:

\documentclass{book}
\newtheorem{theorem}{Theorem}
\makeatletter
\renewcommand*{\@opargbegintheorem}[3]{\trivlist
      \item[\hskip \labelsep{\bfseries #1\ #2}] \textbf{(#3)}\ \itshape}
\makeatother
\begin{document}
\begin{theorem}[This theorem has a very long title which requires a line break]
text
\end{theorem}
\end{document}

theorem with line break in header

So much for information. I recommend using a capable theorem package such as amssthm or ntheorem which extends LaTeX's theorem capabilities.

  • 2
    Perhaps you should mention that ntheorem doesn't solve this "too long title" problem and that your hack won't work with it. On the other hand, amsthm doesn't any problem at all with this kind of thing. – Philippe Goutet Sep 25 '11 at 20:35
  • @Philippe: Yes, it's just a fix of an internal macro. If a theorem package would be used, the situation has to be revisited. As you confirm, no problem with amsthm, I assume it can be solved with ntheorem as well. When I've got some time, I could add a fix as well. For now especially my recommendation of using a capable package stands, which is always better than a "hack", and I prefer amsthm , as mentioned here. – Stefan Kottwitz Sep 25 '11 at 21:02
0

As there have been some comments about providing a fix for ntheorem, I tried to provide one. It seems to work – at least in a quick test – but I am not sure whether it is 100% correct (for example it may break some internal conventions of some packages).

% https://tex.stackexchange.com/a/179917:
\newcommand*{\NLS}{%
    \par
    \nobreak
    \vspace{-\parskip}%
    \noindent
    \ignorespaces
}

\makeatletter
% From ‘ntheorem.sty’:
\newtheoremstyle{mybreak}%
{\item[\rlap{\vbox{\hbox{\hskip\labelsep \theorem@headerfont
                ##1\ ##2\theorem@separator}\hbox{\strut}}}]}%
{\item[\hskip\labelsep \theorem@headerfont%
    ##1\ ##2]\hspace*{-\labelsep}{\theorem@headerfont\ (##3)\theorem@separator}\NLS}
\makeatother

MWE:

\documentclass{book}
\usepackage[standard]{ntheorem}

% https://tex.stackexchange.com/a/179917:
\newcommand*{\NLS}{%
    \par
    \nobreak
    \vspace{-\parskip}%
    \noindent
    \ignorespaces
}

\makeatletter
% From ‘ntheorem.sty’:
\newtheoremstyle{mybreak}%\newtheoremstyle{break}%
{\item[\rlap{\vbox{\hbox{\hskip\labelsep \theorem@headerfont
                ##1\ ##2\theorem@separator}\hbox{\strut}}}]}%
{\item[\hskip\labelsep \theorem@headerfont%{\item[\rlap{\vbox{\hbox{\hskip\labelsep \theorem@headerfont
    ##1\ ##2]\hspace*{-\labelsep}{\theorem@headerfont\ (##3)\theorem@separator}\NLS}%##1\ ##2]\hspace*{-\labelsep}{\theorem@headerfont\ (##3)\theorem@separator}\hfill\penalty\@endparpenalty%##1\ ##2\ (##3)\theorem@separator}\hbox{\strut}}}]}
\makeatother

\theoremstyle{mybreak}
\renewtheorem{Theorem}{Theorem}

\usepackage[all]{nowidow}

% For testing:
\usepackage[english]{babel}
\usepackage{blindtext}
\blindmathtrue

\begin{document}
    \begin{Theorem}[This theorem has a very long title which requires a line break]
        \blindtext\par
        \blindtext
    \end{Theorem}
    \blindtext\par
    \blindtext
\end{document}

Theorem – result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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