巧妙引用定理列表

巧妙引用定理列表

我希望能够自动解决使用 引用包含列表的定理环境的问题cleveref。换句话说,如果推论 1.2 包含部分 (a) 和 (b),那么\cref在引用该定理部分时,我希望输出“推论 1.2(a)”。在证明和类似情况下,我希望能够引用“部分 (a)”,而不必在前面加上“1.2”。

大部分解决方案已在这个优秀的答案,其中包含以下示例。但是,如您所见,我不能只写“(a)”,而不附加“1.2”部分。如何修改这个解决方案,以允许引用单个定理部分而无需获取定理编号?

编辑:我可能会补充说,我实际上将使用该ntheorem包来生成定理,但我认为它实际上不会改变解决方案中的任何内容。我认为最好是在现有示例的基础上进行构建。

在此处输入图片描述

\documentclass[english]{amsart}
\usepackage{babel}
\usepackage{enumitem}  % for '\newlist' and '\setlist' macros
\usepackage[colorlinks=true]{hyperref}
%%\usepackage{amsthm}  % is loaded automatically by amsart document class
\usepackage[nameinlink]{cleveref}

\newtheorem{thm}{Theorem}[section]
\crefname{thm}{Thm.}{Thms.} % singular and plural forms of label

\newtheorem{cor}[thm]{Corollary}
\crefname{cor}{Cor.}{Cors.} % singular and plural forms of label

\newlist{enumthm}{enumerate}{1} % set up a dedicated enumeration env.
\setlist[enumthm]{label=\upshape(\alph*),ref=\upshape\thethm(\alph*)}
\crefalias{enumthmi}{thm} % alias 'enumthmi' counter to 'thm'

\newlist{enumcor}{enumerate}{1} % set up a second dedicated enumeration env.
\setlist[enumcor]{label=\upshape(\alph*),ref=\upshape\thecor(\alph*)}
\crefalias{enumcori}{cor} % alias 'enumcori' counter to 'cor'


\begin{document}
\setcounter{section}{1} % just for this example

\begin{thm}\label{Thm:One}
The following properties hold:
\begin{enumthm}
    \item\label{Thm:One:1} \(1>0\)
    \item\label{Thm:One:2} \(0<1\)
\end{enumthm}
\end{thm}

\begin{cor}\label{Thm:Two}
The following properties hold as well:
\begin{enumcor}
    \item\label{Thm:Two:1} \(2>1\)
    \item\label{Thm:Two:2} \(1<2\)
\end{enumcor}
\begin{proof}
\ref{Thm:Two:1} follows from \ref{Thm:One:1} by adding 1 on both sides. Similarly, \cref{Thm:Two:2} follows from \cref{Thm:One:2}.
\end{proof}
\end{cor}

\end{document} 

答案1

cleveref 存储枚举计数器的值。您可以提取它们,然后格式化它们(我没有尝试添加链接,但这是可能的):

\documentclass[english]{amsart}
\usepackage{babel}
\usepackage{enumitem}  % for '\newlist' and '\setlist' macros
\usepackage[colorlinks=true]{hyperref}
%%\usepackage{amsthm}  % is loaded automatically by amsart document class
\usepackage[nameinlink]{cleveref}

\newtheorem{thm}{Theorem}[section]
\crefname{thm}{Thm.}{Thms.} % singular and plural forms of label

\newtheorem{cor}[thm]{Corollary}
\crefname{cor}{Cor.}{Cors.} % singular and plural forms of label

\newlist{enumthm}{enumerate}{1} % set up a dedicated enumeration env.
\setlist[enumthm]{label=\upshape(\alph*),ref=\upshape\thethm(\alph*)}
\crefalias{enumthmi}{thm} % alias 'enumthmi' counter to 'thm'

\newlist{enumcor}{enumerate}{1} % set up a second dedicated enumeration env.
\setlist[enumcor]{label=\upshape(\alph*),ref=\upshape\thecor(\alph*)}
\crefalias{enumcori}{cor} % alias 'enumcori' counter to 'cor'


\makeatletter
\newcounter{subcreftmpcnt} %
\newcommand\alphsubformat[1]{(\alph{#1})} %adapt ....
\newcommand\subcref[2][\alphsubformat]{%
\ifcsname r@#2@cref\endcsname
  \cref@getcounter {#2}{\mylabel}%
  \setcounter{subcreftmpcnt}{\mylabel}%
  \alphsubformat{subcreftmpcnt}%
 \else ?? \fi}   
\makeatother
\begin{document}
\setcounter{section}{1} % just for this example

\begin{thm}\label{Thm:One}
The following properties hold:
\begin{enumthm}
    \item\label{Thm:One:1} \(1>0\)
    \item\label{Thm:One:2} \(0<1\)
\end{enumthm}
\end{thm}



\begin{cor}\label{Thm:Two}
The following properties hold as well:
\begin{enumcor}
    \item\label{Thm:Two:1} \(2>1\)
    \item\label{Thm:Two:2} \(1<2\)
\end{enumcor}
\begin{proof}
\subcref{Thm:Two:1} follows from \ref{Thm:One:1} by adding 1 on both sides. Similarly,  \subcref{Thm:Two:2}  follows from \cref{Thm:One:2}.


\end{proof}
\end{cor}



\end{document} 

在此处输入图片描述

答案2

我对您的要求和目标的解释如下。首先,文档中有一个或多个重要的定理类环境(例如“定理”),这些环境可能有多个部分。当单独交叉引用这些部分时,交叉引用应显示完整(即复合)数字以及标签“定理”。其次,还有其他不太重要的定理类环境(例如“推论”),这些环境也可能有多个部分。但是,当交叉引用不太重要的环境的部分时,应仅显示子数字(或字母),而不是完整的复合数字。此外,应使用单词“部分”而不是“推论”作为标签前缀。

如果这种理解是正确的,则以下代码应该可以完成您想要的操作。(如果您不希望标签名称成为超目标的一部分,请nameinlink在加载时删除该选项cleveref。)

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{enumitem}  % for '\newlist' and '\setlist' macros
\usepackage[colorlinks=true]{hyperref}
\usepackage[nameinlink]{cleveref}

\newtheorem{thm}{Theorem}[section]
\newtheorem{cor}[thm]{Corollary}

\newlist{enumthm}{enumerate}{1} % a dedicated enum. env.
   \setlist[enumthm]{label=\upshape(\alph*),
                     ref=\upshape\thethm(\alph*)}
\newlist{enumcor}{enumerate}{1} % another dedicated enum. env.
   \setlist[enumcor]{label=\upshape(\alph*)}

\crefname{thm}{Thm.}{Thms.}
\crefname{cor}{Cor.}{Cors.}
\crefname{enumthmi}{Thm.}{Thms.}
\crefname{enumcori}{part}{parts}

\begin{document}
\setcounter{section}{1} % just for this example

\begin{thm}\label{Thm:One}
The following properties hold:
\begin{enumthm}
    \item\label{Thm:One:a} $1>0$
    \item\label{Thm:One:b} $0<1$
\end{enumthm}
\end{thm}

\begin{cor}\label{Thm:Two}
The following properties hold as well:
\begin{enumcor}
    \item\label{Thm:Two:a} $2>1$
    \item\label{Thm:Two:b} $1<2$
\end{enumcor}
\begin{proof}
\Cref{Thm:Two:a} follows from \cref{Thm:One:a} by adding 1 on both sides. Similarly, \cref{Thm:Two:b} follows from \cref{Thm:One:b}.
\end{proof}
\end{cor}

\Cref{Thm:One:a,Thm:One:b} \dots;
\cref{Thm:Two:a,Thm:Two:b} of \cref{Thm:Two} \dots
\end{document}

相关内容