2

I would like to know a way to use newtheorem* and use cref on the labelled theorem. cleveref doesn't seem to work nicely with this * variant.

Example resulting in "cref reference format for label type `' undefined":

\documentclass{article}
\usepackage{amsthm}
\usepackage{cleveref}

\theoremstyle{definition} \newtheorem {hey}{Sandwich}
\theoremstyle{definition} \newtheorem*{hi}{Creek}

\begin{document}
\begin{hey}\label{sand}
aa
\end{hey}

\begin{hi}\label{dirt}
bb
\end{hi}

\cref{sand} % Sandwich 1

\cref{dirt} % warning and results in ??; want: Creek

\end{document}
  • \newtheorem* defines a numberless theorem and \label in the hi environment essentially points to a random reference. What do you expect \cref{dirt} to output? – egreg Nov 10 '19 at 23:29
  • @egreg I am expecting \cref{dirt} to output "Creek", just as \cref{sand} outputs "Sandwich 1", but without the numbering. – Sean P Nov 10 '19 at 23:34
  • If you use “Creek” more than once, what would be the usefulness of this? If it is a one-instance statement, you don't need \cref, do you? – egreg Nov 11 '19 at 0:51
  • @egreg Well other than things like hyperref and keeping to a format for all theorems, numbered or not, I'm also doing it for convenience when I need to tweak names and when the name is awfully long and I refer to it often. – Sean P Nov 11 '19 at 1:23
  • @egreg If there are complete alternatives, I would love to know. I'm pretty new to latex, having created 3 documents in total with it. – Sean P Nov 11 '19 at 1:35
1

Since \newtheorem* doesn't allocate a counter, using \cref will not work. If you just want to abbreviate a long name, use a macro:

\documentclass{article}
\usepackage{amsthm}
\usepackage{cleveref}

\theoremstyle{definition}
\newtheorem {hey}{Sandwich}
\newcommand{\CR}{Creek}
\newtheorem*{hi}{\CR}

\begin{document}
\begin{hey}\label{sand}
aa
\end{hey}

\begin{hi}
bb
\end{hi}

\cref{sand} % Sandwich 1

\CR % Creek

\end{document}

enter image description here

On the other hand you might have several named theorems, and using cleveref will help.

\documentclass{article}
\usepackage{amsthm}
\usepackage{cleveref}

\theoremstyle{definition}
\newtheorem {hey}{Sandwich}

\newtheoremstyle{named}
  {\topsep}     % ABOVESPACE
  {\topsep}     % BELOWSPACE
  {\normalfont} % BODYFONT
  {0pt}         % INDENT (empty value is the same as 0pt)
  {\bfseries}   % HEADFONT
  {.}           % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {\thmname{#1}} % CUSTOM-HEAD-SPEC
\theoremstyle{named}
\newtheorem{namedinner}{\protect\thenamedinner}
\newenvironment{named}[1]
 {\renewcommand{\thenamedinner}{#1}\namedinner}
 {\endnamedinner}
\crefformat{namedinner}{#2#1#3}

\begin{document}
\begin{hey}\label{sand}
aa
\end{hey}

\begin{named}{Creek}\label{dirt}
bb
\end{named}

\begin{named}{River}\label{rain}
cc
\end{named}

\cref{sand} % Sandwich 1

\cref{dirt} % Creek

\cref{rain} % River

\end{document}

enter image description here

|improve this answer|||||

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.