8

I use different theorem enviroments that should in theory all have the same style due to my code. They do as long as I don't load the cleveref package. If I load it, only corollary stays the same. How can I make cleveref to behave ( = to not disturb the styles) ?!

\documentclass{amsbook}
\usepackage{amsmath}
\usepackage{cleveref}
\theoremstyle{plain}
\newtheorem{corollary}{Corollary}\numberwithin{corollary}{chapter}
\newtheorem{example}[corollary]{Example}
\newtheorem{lemma}[corollary]{Lemma}
\begin{document}

\begin{corollary}
A corollary.
\end{corollary}

\begin{example}
An example.
\end{example}

\begin{lemma}
A lemma.
\end{lemma}

\end{document}

The messed up version looks like this:

enter image description here

And what I want is that all theorem environments look like the corollary. As I said, they do if I don't load cleveref.

1
  • 1
    Load cleveref after the styles!
    – user31729
    Oct 25, 2015 at 14:37

2 Answers 2

8

In my opinion the amsbook class takes the wrong approach about theorems: it defines a slightly different structure from amsthm and fakes this package being loaded, so putting cleveref at stake, because this package does as if amsthm were actually loaded.

My solution is to forget about the setup made by the class and returning to amsthm, defining a new theorem style that emulates what amsbook does to begin with. A bit complicated, but it ensures cooperation with cleveref.

\documentclass{amsbook}

\usepackage{amsmath}

% nullify amsbook setup about theorems
\expandafter\let\csname [email protected]\endcsname\relax
\let\theoremstyle\relax
\let\newtheoremstyle\relax
\let\pushQED\relax
\let\popQED\relax
\let\qedhere\relax
\let\mathqed\relax
\let\openbox\relax
\let\proof\relax\let\endproof\relax
\usepackage{amsthm}
\usepackage{cleveref}

% make a new setup that emulates `amsbook`
\makeatletter
\renewcommand{\thm@space@setup}{% like amsbook does
  \thm@preskip=.5\baselineskip\@plus.2\baselineskip \@minus.2\baselineskip
  \thm@postskip=\thm@preskip
}
\newtheoremstyle{amsplain}
{\thm@preskip}
{\thm@postskip}
{\itshape}
{\parindent}
{\scshape}
{.}
{ }
{}
\makeatother

\theoremstyle{amsplain}
\newtheorem{corollary}{Corollary}[chapter]
\newtheorem{example}[corollary]{Example}
\newtheorem{lemma}[corollary]{Lemma}

\begin{document}

Some text before so that it shows indentation
and let's go on until the text breaks across lines
to show also the left margin.

\begin{corollary}
A corollary.
\end{corollary}

\begin{example}
An example.
\end{example}

\begin{lemma}
A lemma.
\end{lemma}

\end{document}

enter image description here

2
  • Works for me, but only if I load cleveref last. If I load it at the same spot where you do (in my actual document), I get a lot of ?? as references.
    – Kjara
    Oct 25, 2015 at 16:36
  • @Kjara cleveref should always be the last package
    – egreg
    Oct 25, 2015 at 16:46
6

cleveref does a lot of sophisticated things with counters and references, using it before \newtheorem{example} etc. will not inform cleveref that example should use the corollary counter etc. (the same for lemma too then)

General rule: Load cleveref as the last package, even after hyperref!!!

\documentclass{amsbook}
\usepackage{amsmath}

\theoremstyle{plain}
\newtheorem{corollary}{Corollary}\numberwithin{corollary}{chapter}
\newtheorem{example}[corollary]{Example}
\newtheorem{lemma}[corollary]{Lemma}


\usepackage{cleveref}

\begin{document}

\begin{corollary}
A corollary.
\end{corollary}

\begin{example}
An example.
\end{example}

\begin{lemma}
A lemma.
\end{lemma}

\end{document}

enter image description here

2
  • 2
    Unfortunately, does not work. Yes, it fixes the theorem styles, but the references (I mainly use \Cref) do not work anymore! I only get a lot of ?? for most (not all) references.
    – Kjara
    Oct 25, 2015 at 16:32
  • @Kjara: \Cref works! If this is not the case for your document, there is apparently something wrong with it, but I don't know what you did in it. It would have been nice to give me a chance to 'correct' something, but now another answer is accepted. :-(
    – user31729
    Oct 25, 2015 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .