考虑以下 MWE
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{enumitem}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}[Great result]
\label{th:great}
Let 1 be the number one.
Then:
\begin{enumerate}[label=\alph*), ref={\ref{th:great}.\alph*}]
\item if $x=1$ and $y=x$, then $y=1$;
\label{th:x-eq-y}
\item if $x<1$ and $y=x$, then $y<1$.
\end{enumerate}
\end{theorem}
\begin{theorem}[Lesser result]
\label{th:lesser}
Let 0 be the number zero.
Then:
\begin{enumerate}[label=\alph*), ref={\ref{th:lesser}.\alph*}]
\item if $x=0$ and $y=x$, then $y=0$;
\label{th:other}
\item if $x<0$ and $y=x$, then $y<0$.
\end{enumerate}
\end{theorem}
Wow, that Theorem~\ref{th:great} was great.
Proving Theorem~\ref{th:x-eq-y} was particularly challenging, much more than Theorem~\ref{th:other}.
\end{document}
它按预期工作。
如何使用\newlist
/定义新列表\setlist
,以便根据周围theorem
环境的 ref 适当地设置 ref?
理想情况下,我希望能够只写
\begin{theorem}[Great result]
\label{th:great}
Let 1 be the number one.
Then:
\begin{thenumerate}
\item if $x=1$ and $y=x$, then $y=1$;
\label{th:x-eq-y}
\item if $x<1$ and $y=x$, then $y<1$.
\end{thenumerate}
\end{theorem}
并得到\ref{th:x-eq-y}
产品“1.a”。
答案1
使用\thetheorem
:
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{enumitem}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newenvironment{thenumerate}[1][]
{\enumerate[label=\alph*\textup{)},ref=\thetheorem.\alph*),#1]}
{\endenumerate}
\begin{document}
\begin{theorem}[Great result]
\label{th:great}
Let $1$ be the number one. Then:
\begin{thenumerate}
\item\label{th:x-eq-y} if $x=1$ and $y=x$, then $y=1$;
\item if $x<1$ and $y=x$, then $y<1$.
\end{thenumerate}
\end{theorem}
\begin{theorem}[Lesser result]
\label{th:lesser}
Let $0$ be the number zero. Then:
\begin{thenumerate}
\item\label{th:other} if $x=0$ and $y=x$, then $y=0$;
\item if $x<0$ and $y=x$, then $y<0$.
\end{thenumerate}
\end{theorem}
Wow, that Theorem~\ref{th:great} was great. Proving Theorem~\ref{th:x-eq-y} was
particularly challenging, much more than Theorem~\ref{th:other}.
\end{document}
只要你根据环境对类似定理的环境进行编号theorem
,比如
\newtheorem{lemma}[theorem]{Lemma}
继承正确的号码不会有问题。
以下变体也适用于不同环境的不同计数器。如果在同一级别有显式计数器,则会出错\refstepcounter
(这通常不会发生)。
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{enumitem}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\makeatletter
\newenvironment{thenumerate}[1][]
{\edef\thistheorem{\@currentlabel}%
\enumerate[label=\alph*\textup{)},ref=\thistheorem.\alph*),#1]}
{\endenumerate}
\makeatother
\begin{document}
\begin{theorem}[Great result]
\label{th:great}
Let $1$ be the number one. Then:
\begin{thenumerate}
\item\label{th:x-eq-y} if $x=1$ and $y=x$, then $y=1$;
\item if $x<1$ and $y=x$, then $y<1$.
\end{thenumerate}
\end{theorem}
\begin{lemma}[Lesser result]
\label{th:lesser}
Let $0$ be the number zero. Then:
\begin{thenumerate}
\item\label{th:other} if $x=0$ and $y=x$, then $y=0$;
\item if $x<0$ and $y=x$, then $y<0$.
\end{thenumerate}
\end{lemma}
Wow, that Theorem~\ref{th:great} was great. Proving Theorem~\ref{th:x-eq-y} was
particularly challenging, much more than Lemma~\ref{th:other}.
\end{document}
答案2
这只是对 egregs 答案的补充。没有理由为此使用额外的环境。只要我们在环境中,就添加额外的配置theorem
。缺点:这必须添加到每个类似环境的 thm 中。
我用它来控制教学材料等中的枚举格式是否一致。
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{enumitem,etoolbox}
\SetEnumitemKey{:thmrefs}{
label=\alph*\textup{)},
ref=\thetheorem.\alph*)
}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\AtBeginEnvironment{theorem}{
\setlist*[enumerate]{:thmrefs}
}
\begin{document}
\begin{theorem}[Great result]
\label{th:great}
Let $1$ be the number one. Then:
\begin{enumerate}
\item\label{th:x-eq-y} if $x=1$ and $y=x$, then $y=1$;
\item if $x<1$ and $y=x$, then $y<1$.
\end{enumerate}
\end{theorem}
\begin{theorem}[Lesser result]
\label{th:lesser}
Let $0$ be the number zero. Then:
\begin{enumerate}
\item\label{th:other} if $x=0$ and $y=x$, then $y=0$;
\item if $x<0$ and $y=x$, then $y<0$.
\end{enumerate}
\end{theorem}
Wow, that Theorem~\ref{th:great} was great. Proving Theorem~\ref{th:x-eq-y} was
particularly challenging, much more than Theorem~\ref{th:other}.
\end{document}