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!

Kolmin
  • 559
  • 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 – David Carlisle Nov 05 '23 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 Nov 05 '23 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. – David Carlisle Nov 05 '23 at 21:20

1 Answers1

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}

Mico
  • 506,678
David Carlisle
  • 757,742
  • Thanks a lot, anyway: much appreciated! :) – Kolmin Nov 05 '23 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 Nov 05 '23 at 21:33
  • @Mico er if you say so, I have never actually used cref apart from the occasional answer here, can you edit this answer? – David Carlisle Nov 05 '23 at 21:39
  • Thanks a lot for all the feedbacks: I was implementing the – brilliant – answer! – Kolmin Nov 05 '23 at 21:47
  • 1
    Happy to oblige. :-) – Mico Nov 05 '23 at 22:16
  • 2
    @Mico thanks... – David Carlisle Nov 05 '23 at 22:16
  • I have a – most probably – silly question. I am trying to implement @egreg answer from this question (https://tex.stackexchange.com/questions/613866/theorem-like-environment-with-optional-title) to polish the MWE and get rid of the round brackets when there is no name in the test, but it doesn't work and I get something along the following lines "T1ifnotempty [...etc]". How can this be fixed? – Kolmin Nov 06 '23 at 10:48
  • 1
    @Kolmin probably you have not used \makeatletter so \@ifnotempty parsed as \@ ifnotempty and typesets ifnotempty – David Carlisle Nov 06 '23 at 11:15
  • Brilliant! Thanks a lot: much (much) appreciated! – Kolmin Nov 06 '23 at 13:40