4

I have a problem with the presence of an unwanted space when I use amsthm and cleveref.

The following is a MWE that highlights the issue.

\documentclass{article}

\usepackage[english]{babel}

\usepackage{amsthm}
\usepackage[hypertexnames=false]{hyperref}
\usepackage[noabbrev,nameinlink]{cleveref}

\hypersetup{colorlinks=true,linkcolor={red}}

\newtheoremstyle{test}{}{}{\itshape}{}{\bfseries}{.}{.5em}{#1#2 (\thmnote{#3})}
\theoremstyle{test}
\newtheorem{test}{Test T}

\begin{document}

\begin{test}[Test Name]
\label{test}
Test.
\end{test}

\Cref{test}.

\end{document}

As it can be noticed, where I would like to obtain with Cref "Test T1", I actually get "Test T 1".

Any feedback will be most welcome!

3
  • 2
    shouldn't the T be part of the counter format not the environment name?, you currently get a space for the same reason you would get Theorem 1 not Theorem1 Commented Nov 5, 2023 at 21:09
  • Thanks a lot for the immediate reply! I see. However, my problem is that I would like to use that newtheoremstyle with various newtheorem, so to speak, all with different letters (e.g., S, T, etc), but sharing the same newtheoremstyle, without being forced to define a new one for every letter (if possible at all).
    – Kolmin
    Commented Nov 5, 2023 at 21:16
  • well I don't really know cleveref that well to be honest I answered with the classic latex view that the counter would be T1 here (or at least I think that's the classic view) but feel free not to accept, someone knowing more cleveref tricks may give a different answer. Commented Nov 5, 2023 at 21:20

1 Answer 1

6

I think you are looking for something like:

enter image description here

\documentclass{article}

\usepackage[english]{babel}

\usepackage{amsthm}
\usepackage[colorlinks,linkcolor=red]{hyperref}
\usepackage[noabbrev,nameinlink]{cleveref}

\newtheoremstyle{test}{}{}{\itshape}{}{\bfseries}{.}{.5em}{#1 #2 (\thmnote{#3})}
\theoremstyle{test}
\newtheorem{test}{Test}
\renewcommand\thetest{T\arabic{test}}
\crefname{test}{Test}{Tests} % for \cref and \Cref calls with more than 1 arg.

\begin{document}

\begin{test}[Test Name] \label{testa} Test. \end{test}
\begin{test}[Another Test] \label{testb} Another test. \end{test}

\Cref{testa}.

\Cref{testa,testb}.

\end{document}
9
  • Thanks a lot, anyway: much appreciated! :)
    – Kolmin
    Commented Nov 5, 2023 at 21:32
  • 1
    +1. I think it would be useful to run \crefname{test}{Test}{Tests} immediately after \renewcommand\thetest{T\arabic{test}}, in order to enable the sucessful execution of an instruction of the form \cref{testa,testb}.
    – Mico
    Commented Nov 5, 2023 at 21:33
  • 1
    Happy to oblige. :-)
    – Mico
    Commented Nov 5, 2023 at 22:16
  • 2
    @Mico thanks... Commented Nov 5, 2023 at 22:16
  • 1
    @Kolmin probably you have not used \makeatletter so \@ifnotempty parsed as \@ ifnotempty and typesets ifnotempty Commented Nov 6, 2023 at 11:15

You must log in to answer this question.

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