我正在尝试在定理环境中设置对列表项的引用。使用thm工具和参考文献-package 我能够引用定理环境,使得定理类型(例如定理、引理、推论)显示在参考文献中(参见考试 1)。
使用枚举项-package I 引用定理环境中的列表项,使得定理的编号与参考文献中的项目编号一起显示(参见考试 2)。
现在回答我的问题:有没有一种优雅的方法可以将这两种技术结合起来,从而返回列表项所在环境的定理类型以及定理和项目编号的组合?
当我使用命令时,\autoref{•}
标签类型物品显示(参见考试 3)。这是有道理的,因为我的列表环境列表源自枚举环境。使用\cref{•}
只会产生两个问号(参见考试 4)。
目前,我将类型直接分配给\label
命令作为可选参数(参见考试 5)。但这个解决方案要求我对定理类型进行硬编码,加上纺织机械制造商无法识别标签。
因为我喜欢将我的定理分成几个部分,所以这个问题的优雅解决方案将非常方便。
如有任何提示或答复我将不胜感激。
\documentclass[10pt,a4paper]{article}
% Input Type and AMS-Packages
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
% Typography
\usepackage{enumitem}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}), ref=\thethm.(\roman{thmlisti}),noitemsep}
% Math, Operators and Theorems
\usepackage{thmtools}
\declaretheorem[
name=Theorem,
%refname={theorem,theorems}, %Lower Case Versions of Theorem Type
Refname={Theorem,Theorems},
numberwithin=section]{thm}
\declaretheorem[
name=Lemma,
%refname={lemma,lemmas},
Refname={Lemma,Lemmas},
sibling=thm]{lem}
% References
\usepackage{nameref,hyperref}
\usepackage[capitalize]{cleveref}
\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
\begin{document}
\begin{thm}\label{thm:A}
\begin{thmlist}
\item Statment 1\label{thm:A1}
\item Statment 2\label[thm]{thm:A2}
\end{thmlist}
\end{thm}
\begin{lem}\label{thm:B}
\begin{thmlist}
\item Statment 1\label{thm:B1}
\item Statment 2\label[lem]{thm:B2}
\end{thmlist}
\end{lem}
\begin{description}
\item[1:] That's how I refer to theorems and their like: \cref{thm:A} and \cref{thm:B}.
\item[2:] That's how I refer to parts of theorems but without the label type: \ref{thm:A1} and \ref{thm:B1}.
\item[3:] This happens when using \verb+\autoref{•}:+ \autoref{thm:A1} and \autoref{thm:B1}.
\item[4:] This happens when using \verb+\cref{•}:+ \cref{thm:A1} and \cref{thm:B1}.
\item[5:] My current work around: \cref{thm:A2} and \cref{thm:B2}.
\end{description}
\end{document}
答案1
这是根据您的示例进行的尝试。我使用了 定义的定理钩子来覆盖当前环境中的thmtools
格式:thmlisti
\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{thm}}
\addtotheorempostheadhook[lem]{\crefalias{thmlisti}{lem}}
我不能保证它不会破坏任何东西,例如如果你使用thmlist
没有任何周围定理的。
\documentclass[10pt,a4paper]{article}
% Input Type and AMS-Packages
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
% Typography
\usepackage{enumitem}
\usepackage{letltxmacro}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}), ref=\thethm.(\roman{thmlisti}),noitemsep}
% Math, Operators and Theorems
\usepackage{thmtools}
\declaretheorem[
name=Theorem,
%refname={theorem,theorems}, %Lower Case Versions of Theorem Type
Refname={Theorem,Theorems},
numberwithin=section]{thm}
\declaretheorem[
name=Lemma,
%refname={lemma,lemmas},
Refname={Lemma,Lemmas},
sibling=thm]{lem}
% References
\usepackage{nameref,hyperref}
\usepackage[capitalize]{cleveref}
\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
%%% NEW
\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{thm}}
\addtotheorempostheadhook[lem]{\crefalias{thmlisti}{lem}}
\begin{document}
\begin{thm}\label{thm:A}
\begin{thmlist}
\item Statment 1\label{thm:A1}
\item Statment 2\label[thm]{thm:A2}
\end{thmlist}
\end{thm}
\begin{lem}\label{thm:B}
\begin{thmlist}
\item Statment 1\label{thm:B1}
\item Statment 2\label[lem]{thm:B2}
\end{thmlist}
\end{lem}
\begin{description}
\item[1:] That's how I refer to theorems and their like: \cref{thm:A} and \cref{thm:B}.
\item[2:] That's how I refer to parts of theorems but without the label type: \ref{thm:A1} and \ref{thm:B1}.
\item[3:] This happens when using \verb+\autoref{•}:+ \autoref{thm:A1} and \autoref{thm:B1}.
\item[4:] This happens when using \verb+\cref{•}:+ \cref{thm:A1} and \cref{thm:B1} (now working)
\item[5:] My current work around: \cref{thm:A2} and \cref{thm:B2}.
\end{description}
\end{document}
答案2
这是一个解决方案。
定义新列表lemlist
\newlist{lemlist}{enumerate}{1}
\setlist[lemlist]{label=(\roman{lemlisti}), ref=\thethm.(\roman{lemlisti}),noitemsep}
并在里面使用这个lem
。
然后,声明
\Crefname{thmlisti}{Theorem}{Theorems}
\Crefname{lemlisti}{Lemma}{Lemmas}
并且您将能够避免\label
s 的可选参数。
梅威瑟:
\documentclass[10pt,a4paper]{article}
% Input Type and AMS-Packages
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
% Typography
\usepackage{enumitem}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}), ref=\thethm.(\roman{thmlisti}),noitemsep}
\newlist{lemlist}{enumerate}{1}
\setlist[lemlist]{label=(\roman{lemlisti}), ref=\thethm.(\roman{lemlisti}),noitemsep}
% Math, Operators and Theorems
\usepackage{thmtools}
\declaretheorem[
name=Theorem,
%refname={theorem,theorems}, %Lower Case Versions of Theorem Type
Refname={Theorem,Theorems},
numberwithin=section]{thm}
\declaretheorem[
name=Lemma,
%refname={lemma,lemmas},
Refname={Lemma,Lemmas},
sibling=thm]{lem}
% References
\usepackage{nameref,hyperref}
\usepackage[capitalize]{cleveref}
\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
\Crefname{thmlisti}{Theorem}{Theorems}
\Crefname{lemlisti}{Lemma}{Lemmas}
\begin{document}
\begin{thm}\label{thm:A}
\begin{thmlist}
\item Statment 1\label{thm:A1}
\item Statment 2\label{thm:A2}
\end{thmlist}
\end{thm}
\begin{lem}\label{thm:B}
\begin{lemlist}
\item Statment 1\label{thm:B1}
\item Statment 2\label{thm:B2}
\end{lemlist}
\end{lem}
\begin{description}
\item[1:] That's how I refer to theorems and their like: \cref{thm:A} and \cref{thm:B}.
\item[2:] That's how I refer to parts of theorems but without the label type: \ref{thm:A1} and \ref{thm:B1}.
\item[3:] This happens when using \verb+\autoref{•}:+ \autoref{thm:A1} and \autoref{thm:B1}.
\item[4:] This happens when using \verb+\cref{•}:+ \cref{thm:A1} and \cref{thm:B1}.
\item[5:] My current work around: \cref{thm:A2} and \cref{thm:B2}.
\end{description}
\end{document}
输出:
答案3
我能够改进@T.Verron 的出色回答,以便\ref
返回列表环境的普通计数器,同时\cref
返回包含类型、定理数量和列表计数器的完整标签(请参阅我对@T.Verron 的回答的评论)。
为此,我设立了两个新计数器
\newcounter{listthm}
\newcounter{listlem}
其名称与我想要使用它们的定理环境相对应
\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
\Crefname{listthm}{Theorem}{Theorems}
\Crefname{listlem}{Lemma}{Lemmas}
在定理中头柱钩的样式thmlisti
现在分别设置为listthm
或listlem
。
\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{listthm}}
\addtotheorempostheadhook[lem]{\crefalias{thmlisti}{listlem}}
关键的一步是,我现在能够修改和的标签格式listthm
,而不会影响和仅使用-package提供的命令listlem
的格式thm
lem
cref
\creflabelformat{listthm}{#2\thethm.#1#3}
\creflabelformat{listlem}{#2\thethm.#1#3}
现在我可以避免设置使用-packageref
的-style ,这会导致-command也返回该定理的计数器。thmlisti
enumitem
\ref
欲了解完整详情,请参阅下面的示例。
\documentclass[10pt,a4paper]{article}
% Input Type and AMS-Packages
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
% Typography
\usepackage{enumitem}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}),noitemsep}
% Math, Operators and Theorems
\usepackage{thmtools}
\declaretheorem[
name=Theorem,
numberwithin=section]{thm}
\declaretheorem[
name=Lemma,
sibling=thm]{lem}
% References
\usepackage{hyperref}
\usepackage[capitalize]{cleveref}
\newcounter{listthm}
\newcounter{listlem}
\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
\Crefname{listthm}{Theorem}{Theorems}
\Crefname{listlem}{Lemma}{Lemmas}
\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{listthm}}
\addtotheorempostheadhook[lem]{\crefalias{thmlisti}{listlem}}
\creflabelformat{listthm}{#2\thethm.#1#3}
\creflabelformat{listlem}{#2\thethm.#1#3}
\begin{document}
\begin{thm}\label{thm:A}
\begin{thmlist}
\item Statment 1\label{thm:A1}
\item Statment 2\label{thm:A2}
\end{thmlist}
\end{thm}
\begin{lem}\label{thm:B}
\begin{thmlist}
\item Statment 1\label{thm:B1}
\item Statment 2\label{thm:B2}
\end{thmlist}
\end{lem}
\begin{enumerate}
\item That's how I refer to theorems and their like: \cref{thm:A} and \cref{thm:B}.
\item Referring to parts of theorems works like a charm with \verb+\cref{•}:+ \cref{thm:A1} and \cref{thm:B1}.
\item If I use \verb+\ref{•}+ to refer to a part of a theorem \LaTeX{} returns \ref{thm:A1} and \ref{thm:B2}.
\end{enumerate}
\end{document}
答案4
这是一个固定版本tim6her 的回答。该答案中的问题是,它\creflabelformat{listthm}{#2\thethm.#1#3}
不从标签中获取计数器,而是使用调用时当前的计数器thm
值。下面提出的修复方法是在用于定理“子项”的命令中进行设置。thm
\cref
ref=\thethm.(\roman{thmlisti})
\setlist[thmlist]{...}
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{enumitem}
\usepackage{thmtools}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}),
ref=\thethm.(\roman{thmlisti}),
noitemsep}
\declaretheorem[
name=Theorem,
numberwithin=section]{thm}
\declaretheorem[
name=Lemma,
sibling=thm]{lem}
% References
\usepackage{hyperref}
\usepackage[capitalize]{cleveref}
\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
\Crefname{listthm}{Theorem}{Theorems}
\Crefname{listlem}{Lemma}{Lemmas}
\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{listthm}}
\addtotheorempostheadhook[lem]{\crefalias{thmlisti}{listlem}}
\begin{document}
\begin{thm}\label{thm:A}
\begin{thmlist}
\item Statment 1\label{thm:A1}
\item Statment 2\label{thm:A2}
\end{thmlist}
\end{thm}
\begin{lem}\label{thm:B}
\begin{thmlist}
\item Statment 1\label{thm:B1}
\item Statment 2\label{thm:B2}
\end{thmlist}
\end{lem}
\begin{lem}\label{thm:C}
\begin{thmlist}
\item Statment 1\label{thm:C1}
\item Statment 2\label{thm:C2}
\item Statment 3\label{thm:C3}
\end{thmlist}
\end{lem}
\begin{enumerate}
\item That's how I refer to theorems and their like: \cref{thm:A} and
\cref{thm:B}.
\item Referring to parts of theorems works like a charm with
\verb|\cref|: \cref{thm:A1} and \cref{thm:B1}.
\item If I use \verb|\ref| to refer to a part of a theorem, \LaTeX\ prints
\ref{thm:A1} and \ref{thm:B2}.
\end{enumerate}
\end{document}