3

I have the same problem as the link use \cref within enumerate and theorem. However, after applying the provided method in the answer box, I found there are two extra spaces before and after my item referred. Help appreciated!

\documentclass[12pt]{article}
\setcounter{secnumdepth}{3} %The secnumdepth value determines up to what level the sectioning titles are numbered
\setcounter{tocdepth}{1} %the tocdepth value determines to which level the sectioning commands are printed in the ToC
\usepackage{mathtools}
\usepackage{amssymb,amsthm}
\usepackage[inline]{enumitem}
\usepackage{hyperref}
\usepackage{cleveref}

\newcommand{\Crefdefpart}[2]{
  \nameCref{#1}~\hyperref[#2]{\labelcref*{#1}\ref*{#2}}
  }
\crefname{enumi}{part}{parts}
\crefname{exercise}{exercise}{exercises}
\crefname{example}{example}{examples}
\newcommand{\crefrangeconjunction}{--}

\theoremstyle{definition}

\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}\label{thm3.10}\leavevmode 
\begin{enumerate}[label = (\alph*)]
    \item\label{thm3.10a} If $\overline{E}$ is the closure of a set $E$ in a metric space $X$, then
    \begin{equation*}
        \operatorname{diam} \overline{E} = \operatorname{diam} E
    \end{equation*}
    \item \label{thm3.10b}If $K_{n}$ is a sequence of compact sets in $X$ such that $K_{n} \supset K_{n+1}$ and if 
    \begin{equation*}
        \lim_{n\to \infty} \operatorname{diam}K_{n} = 0
    \end{equation*}
    then $\bigcap_{n=1}^{\infty}K_{n}$ consists of exactly one point.
\end{enumerate}
\end{theorem}

From \Crefdefpart{thm3.10}{thm3.10a}, we see two extra spaces before and after the theorem.

\end{document}

enter image description here

1
  • 1
    Welcome to TeX.SE.
    – Mico
    Nov 6, 2022 at 3:21

1 Answer 1

3

The culprit is the following construct:

\newcommand{\Crefdefpart}[2]{
  \nameCref{#1}~\hyperref[#2]{\labelcref*{#1}\ref*{#2}}
  }

TeX changes invisible end-of-line characters to whitespace. Because the construct contains two line breaks not terminated by a comment character, you get extra whitespace both before and after the output of the instruction.

The remedy? Insert comment characters, i.e., %, at the ends of both lines:

\newcommand{\Crefdefpart}[2]{%
  \nameCref{#1}~\hyperref[#2]{\labelcref*{#1}\ref*{#2}}%
  }
1
  • 1
    +1, but you’re stealing my job! 😎
    – egreg
    Nov 6, 2022 at 9:20

You must log in to answer this question.

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