我正在尝试编写定理有效所需的条件,以便该条件自动编号并且能够在以后引用(例如,可以使用链接返回到初始条件定义。)
我尝试获取的格式是:
(C1) Statement about the required process
文档中的引用如下:
Following from (C1), we have that blah.
我尝试过类似以下的方法:
\documentclass{article}
\usepackage{cleveref}
\usepackage{amsthm}
% Define new theorem environment that works only with conditions
\newtheorem{Condition}{C}
\crefname{Condition}{C}{C} % singular and plural forms of label
\begin{document}
% Attempt 1
\begin{Condition}
\begin{enumerate}
\item Statement about the required process. \label{cond:test}
\item Next statement about the required process. \label{cond:test2}
\end{enumerate}
\end{Condition}
% Attempt 2
\begin{Condition}
Statement about the required process. \label{cond:test3}
\end{Condition}
(C\ref{cond:test}, \ref{cond:test2}, \ref{cond:test3}
\end{document}
有什么建议么?
答案1
这是一种可能的方法,使用的项目enumerate
并使它们成为subcondition
,使用Condition
计数器作为父级。
“无项目”条件应该使用类似的参考标签,打印为(C2)
等。为了实现这一点,必须更改宏\p@Condition
,以便首先获取计数器名称,然后再附加)
。
\documentclass{article}
\usepackage{amsthm}
\usepackage{enumitem}
\newtheorem{Condition}{C}
\usepackage{hyperref}
\usepackage{cleveref}
\setlist[enumerate,1]{leftmargin={40pt},label=(C\theCondition.\arabic*),ref=(C\theCondition.\arabic*),before={\leavevmode}}
\makeatletter
\def\@grabconditioncounter\csname #1\endcsname{%
(C\csname#1\endcsname)%
}
\renewcommand\p@Condition{\@grabconditioncounter}
\makeatother
\begin{document}
\begin{Condition}
\begin{enumerate}
\item Statement about the required process. \label{cond:test}
\item Next statement about the required process. \label{cond:test2}
\end{enumerate}
\end{Condition}
% Attempt 2
\begin{Condition}
Statement about the required process. \label{cond:test3}
\end{Condition}
Following from \ref{cond:test}, we have that\dots, but \ref{cond:test2} and \ref{cond:test3} are important also.
\end{document}
更新以 (C1) 编号为“定理”头并带有环境的版本。
我已将\setlist
枚举的变化放入环境内部Condition
,以便其他用法enumerate
将不会有“奇怪”的枚举标签。
\documentclass{article}
\usepackage{enumitem}
\newcounter{Condition}
\newenvironment{Condition}{%
\setlist[enumerate,1]{font={\itshape},leftmargin={40pt},label=(C\theCondition.\arabic*),ref=(C\theCondition.\arabic*)}%,before={\leavevmode}}
\parindent=0em
\refstepcounter{Condition}%
\textbf{(C\theCondition)}
%Explicit newline above
}{%
}
\usepackage{hyperref}
\usepackage{cleveref}
\makeatletter
\def\@grabconditioncounter\csname #1\endcsname{%
(C\csname#1\endcsname)%
}
\renewcommand\p@Condition{\@grabconditioncounter}
\makeatother
\begin{document}
\begin{Condition}
\begin{enumerate}
\item Statement about the required process. \label{cond:test}
\item Next statement about the required process. \label{cond:test2}
\end{enumerate}
\end{Condition}
% Attempt 2
\begin{Condition}
Statement about the required process. \label{cond:test3}
\end{Condition}
Following from \ref{cond:test}, we have that\dots, but \ref{cond:test2} and \ref{cond:test3} are important also.
\begin{enumerate}
\item A
\item B
\end{enumerate}
\end{document}