使用 cleveref 进行交叉引用的标记语句

使用 cleveref 进行交叉引用的标记语句

我正在寻找一个命令来自动化条件标签,这样当我移动它们时,我不会因为重新编号而发疯。我尝试使用cleveref功能,但找不到解决方案

\cond{label}我的意思是像这样使用时的命令

\begin{thm}\label{thm:1}
Suppose one (or both) of the following hold:
\cond{cnd:a}  the earth is flat;\\
\cond{cnd:b}  the sun is squared\\
if you believe it, you are not a scientist.
\end{thm}

Conditions \cref{cnd:a} and \cref{cnd:b} in  \cref{thm:1} are pretty stupid

将产生以下输出

在此处输入图片描述

答案1

为了创建对编号对象(如“条件”)的交叉引用,最好创建一个计数器,每次插入条件时计数器都会增加。这可以借助包enumitem及其\newlist宏顺利完成\setlist

在此处输入图片描述

\documentclass{article}
\usepackage{amsthm,enumitem}
\usepackage[noabbrev,capitalize]{cleveref}

\newtheorem{thm}{Theorem}
\newlist{condenum}{enumerate}{1} % create a counter called 'condenumi'
\setlist[condenum,1]{label=\upshape(C\arabic*),nosep} % define appearance of labels
\crefname{condenumi}{condition}{conditions} % name associated with conditions

\begin{document}
\begin{thm}\label{thm:1}
Suppose one (or both) of the following hold:
\begin{condenum} % start a special enumerated list
\item \label{cnd:a}  The earth is flat.
\item \label{cnd:b}  The sun is a square.
\end{condenum}
If you believe it, you are not a scientist.
\end{thm}

\noindent
\Cref{cnd:a,cnd:b} in \cref{thm:1} are pretty stupid.
\end{document}

相关内容