交叉引用子定理时不需要的空格

交叉引用子定理时不需要的空格

我有和链接相同的问题在枚举和定理中使用 \cref。但是,在答案框中应用提供的方法后,我发现我引用的项目前后有两个多余的空格。非常感谢您的帮助!

\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}

在此处输入图片描述

答案1

罪魁祸首是以下构造:

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

TeX 将不可见的行尾字符更改为空格。由于构造包含换行符没有以注释字符结束,您会在指令输出之前和之后得到额外的空格。

%补救措施?在两行末尾插入注释字符,即:

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

相关内容