
이 포스팅은 다음에서 영감을 받아 작성되었습니다.최근 쿼리관련이 있지만 동일하지는 않은 질문을 한 것입니다.
열거된 목록의 레이블을 마치 방정식 번호(왼쪽에 방정식 번호가 있는)인 것처럼 표시하려고 한다고 가정해 보겠습니다. 실제로 목록 항목은 카운터를 공유해야 합니다 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}
이후에 호출하는 것은 너무 늦습니다. 이전에 호출하는 것은 의 내부에서 덮어쓰기 때문에 너무 이르습니다 . 이 작업을 수행할 수 있는 유일한 장소는 by 와 이라는 내부 호출 사이 어딘가입니다 . 나는 당신의 방법을 해킹하지 않고서 이것이 행해질 수 있는 곳을 의 코드에서 전혀 보지 못했습니다 .\item
\item
\refstepcounter
\item
\refstepcounter
\item
\makelabel
enumitem
하지만 카운터로 enumerate
활용 하기에는 충분히 간단합니다 . equation
재설정하고 싶지 않기 때문에 직접 사용할 수는 없지만 대신 be로 \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
.
물론 이것은 약간 기만적이므로 사용에 있어서 어느 정도 자제력을 발휘해야 합니다(예: 네스팅이 예쁘게 나오지 않을 것 등). 그러나 그렇지 않으면 합리적인 방법으로 작업을 완료하는 것 같습니다.