在如何使用 cleveref 获取类似定理的名称和列表项编号?答案提供了一种方法,使\cref
链接在无编号定理类环境中引用项目编号。它使用enumitem
等。
那里给出的例子如下,但这里有一个小的修改,如我所需:实际的项目标签具有由键指定的附加格式label
,即\setlist[problemsenum,1]{...}
命令,即:
label=\bfseries\sffamily\arabic*.
不幸的是,这会导致相应的\cref
链接也包含该格式(粗体、无衬线,后跟句点)。
有没有办法删除链接中的附加格式?
我对该label
密钥进行修改后的源代码如下:
\documentclass[oneside]{book}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{enumitem}
\usepackage[colorlinks,linkcolor=blue]{hyperref} % hyperref added
\usepackage{aliascnt}
\usepackage[nameinlink]{cleveref}
\declaretheoremstyle[
headformat=\NAME\NOTE,
]{probs}
\declaretheorem[
name=PROBLEMS,
style=probs,
]{problemsinner}
\newenvironment{problems}
{\problemsinner Solve these problems.}
{\endproblemsinner}
\newlist{problemsenum}{enumerate}{1}
\setlist[problemsenum,1]{label=\bfseries\sffamily\arabic*.} % label mod here}
\makeatletter
\renewcommand{\p@problemsenumi}{\maybe@thechapter{\thechapter}}
\protected\def\maybe@thechapter#1{%
\ifnum#1=\value{chapter}%
\else
#1.%
\fi
}
\makeatother
\crefformat{problemsenumi}{#2Problem~#1#3}
\Crefformat{problemsenumi}{#2Problem~#1#3}
\crefformat{problemsinner}{#2#3}
\Crefformat{problemsinner}{#2#3}
\begin{document}
\chapter{First}\label{chap:1}
See \cref{prob-part:first-problem} in a different chapter.
\chapter{Second}\label{chap:2}
Refer to \cref{prob-part:first-problem} in this chapter.
\begin{problems}
\label{prob:my-problems}
\begin{problemsenum}
\item \label{prob-part:first-problem}
First problem.
\item
Second problem.
\end{problemsenum}
\end{problems}
\end{document}
如输出页面的这一部分所示,在链接“问题 2.1.”中,“2.1”后面有一个多余的句号,并且“1”和句号都是粗体无衬线字体。我希望那里没有句号,只有正常文本,而不是粗体或无衬线字体。
答案1
但是,更改label=...
类型的更改也被设置为参考值,enumitem
提供了ref=
选项。
如果您不想要粗体/无衬线且没有点,那么说ref={\arabic*}
——这样参考值就只是数字。
\documentclass[oneside]{book}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{enumitem}
\usepackage[colorlinks,linkcolor=blue]{hyperref} % hyperref added
\usepackage{aliascnt}
\usepackage[nameinlink]{cleveref}
\declaretheoremstyle[
headformat=\NAME\NOTE,
]{probs}
\declaretheorem[
name=PROBLEMS,
style=probs,
]{problemsinner}
\newenvironment{problems}
{\problemsinner Solve these problems.}
{\endproblemsinner}
\newlist{problemsenum}{enumerate}{1}
\setlist[problemsenum,1]{label={\bfseries\sffamily\arabic*.},ref={\arabic*}} % label mod here}
\makeatletter
\renewcommand{\p@problemsenumi}{\maybe@thechapter{\thechapter}}
\protected\def\maybe@thechapter#1{%
\ifnum#1=\value{chapter}%
\else
#1.%
\fi
}
\makeatother
\crefformat{problemsenumi}{#2Problem~#1#3}
\Crefformat{problemsenumi}{#2Problem~#1#3}
\crefformat{problemsinner}{#2#3}
\Crefformat{problemsinner}{#2#3}
\begin{document}
\chapter{First}\label{chap:1}
See \cref{prob-part:first-problem} in a different chapter.
\chapter{Second}\label{chap:2}
Refer to \cref{prob-part:first-problem} in this chapter.
\begin{problems}
\label{prob:my-problems}
\begin{problemsenum}
\item \label{prob-part:first-problem}
First problem.
\item
Second problem.
\end{problemsenum}
\end{problems}
\end{document}