使用自動編號和標籤編寫定理條件

使用自動編號和標籤編寫定理條件

我正在嘗試編寫定理有效所需的條件,以便條件自動編號並且能夠在以後引用(例如,可以使用連結返回初始條件定義。)

我試圖取得的格式是:

(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並將它們設為 a 。subconditionCondition

「無項目」條件應使用類似的參考標籤,列印為等(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) 編號作為「定理」頭部和環境的版本。

我已將\setlistenumerate 的更改放入環境中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}

相關內容