
この投稿は、最近のクエリ関連はあるものの、同一ではない質問をしていました。
列挙リストのラベルを方程式の番号のように表示したいとします(方程式の番号は左側に配置されます)。実際には、リスト項目はカウンターを共有することになっていますequation
。次のMWEは、列挙項目パッケージ。
\documentclass{article}
\usepackage[leqno]{amsmath}
\counterwithin{equation}{section}
\usepackage{parskip}
\usepackage{enumitem}
\usepackage[colorlinks,allcolors=red]{hyperref}
\usepackage[nameinlink,noabbrev]{cleveref}
\begin{document}
\setcounter{section}{2} % just for this example
A displayed and numbered equation:
\begin{equation}\label{eq:a}
1+1=2
\end{equation}
and a cross-reference to \cref{eq:a}.
An enumerated list that's ``numbered'' the same way as a displayed equation:
\begin{enumerate}[format=\refstepcounter{equation}, label=(\theequation), left=0pt]
\item First enumerated fact. \label{item:I}
\item Second enumerated fact.
\end{enumerate}
I want to cross-reference \cref{item:I} the same way as \cref{eq:a}.
\end{document}
問題は、列挙された項目は正しく「番号付け」(ラベル付け?)されているが、相互参照が正しく行われていないことです。ちなみに、これは問題ではありません。およびcleveref
でも同じ問題が発生します。\ref
\eqref
質問: 何が足りないのでしょうか?enumitem
パッケージを使用することが重要であることに留意してください。
答え1
特別な環境を定義します。
\documentclass{article}
\usepackage[leqno]{amsmath}
\counterwithin{equation}{section}
\usepackage{enumitem}
\usepackage[colorlinks,allcolors=red]{hyperref}
\usepackage[nameinlink,noabbrev]{cleveref}
% define a proper environment
\newlist{eqlist}{enumerate}{1}
\crefname{eqlisti}{item}{items}
% the counter is shared
\ExpandArgs{cc}\RenewCommandCopy{c@eqlisti}{c@equation}
\setlist[eqlist,1]{
left=0pt, % labels flush left
label=\textup{(\theequation)}, % like for equations
before=\stepcounter{equation}, % we want to go on with numbering
resume, % don't forget the final number
}
\begin{document}
\setcounter{section}{2} % just for this example
A displayed and numbered equation:
\begin{equation}\label{eq:a}
1+1=2
\end{equation}
and a cross-reference to \cref{eq:a}.
An enumerated list that's ``numbered'' the same way as a displayed equation:
\begin{eqlist}
\item First enumerated fact. \label{item:I}
\item Second enumerated fact.
\end{eqlist}
I want to cross-reference \cref{item:I} the same way as \cref{eq:a}.
A displayed and numbered equation:
\begin{equation}\label{eq:b}
1+1=2
\end{equation}
and a cross-reference to \cref{eq:b}.
An enumerated list that's ``numbered'' the same way as a displayed equation:
\begin{eqlist}
\item First enumerated fact. \label{item:I+}
\item Second enumerated fact.
\end{eqlist}
I want to cross-reference \cref{item:I+} the same way as \cref{eq:b}.
\end{document}
答え2
を実行するとformat=\refstepcounter{equation}
、グループ化されている\refstepcounter
内で が呼び出されます。カウンタ自体はもちろんグローバルにステップ実行されますが、次のおよび\makelabel
で使用できるはずの変数はグループが終了すると失われるため、 ではによって設定されたそれらの値を参照しません。\label
\@currentlabel
\@currentcounter
\label{item:I}
\refstepcounter{equation}
さて、\refstepcounter{equation}
の後に\item
(何らかの方法で) を呼び出すのは遅すぎます。アイテムのラベルがすでにタイプセットされているためです。また、 の前に を呼び出すのは\item
早すぎます。\refstepcounter
の 内部によって上書きされてしまうためです。これを行うことができる唯一の場所は、 によって呼び出される内部と\item
の間です。のコードでこれを行うことができる場所は、ハッキングしない限りまったく見当たりません。\refstepcounter
\item
\makelabel
enumitem
enumerate
しかし、カウンターとして使用するには十分シンプルですequation
。リセットしたくないので、 を直接使用することはできません\usecounter
が、代わりに\@listctr
を設定することしかできませんequation
。
\documentclass{article}
\usepackage[leqno]{amsmath}
\counterwithin{equation}{section}
\usepackage{parskip}
\usepackage{enumitem}
\usepackage[colorlinks,allcolors=red]{hyperref}
\usepackage[nameinlink,noabbrev]{cleveref}
\makeatletter
\newcommand{\mysetlistctr}[1]{\def\@listctr{#1}}
\makeatother
\begin{document}
\setcounter{section}{2} % just for this example
A displayed and numbered equation:
\begin{equation}\label{eq:a}
1+1=2
\end{equation}
and a cross-reference to \cref{eq:a}.
An enumerated list that's ``numbered'' the same way as a displayed equation:
\begin{enumerate}[first*=\mysetlistctr{equation}, label=(\theequation), left=0pt]
\item First enumerated fact. \label{item:I}
\item Second enumerated fact.
\end{enumerate}
I want to cross-reference \cref{item:I} the same way as \cref{eq:a}.
\end{document}
\crefalias
、または類似のを改ざんする必要はありません。 は、cleveref
これが通常の であると「信じる」だけですequation
。
もちろん、これは少し巧妙な方法であり、使用にはある程度の自制が必要です (たとえば、ネストするときれいにならないなど)。しかし、それ以外は、妥当な方法で目的を達成できるようです。