enumitem 和 cleveref:如何将素数放入某些括号标签中

enumitem 和 cleveref:如何将素数放入某些括号标签中

后续行动enumitem:如何将素数放入某些括号标签中

在 enumitem 和 cleveref 的上下文中,如何在 (ii) 中的 ii 上添加素数上标?MWE:

\documentclass{article}
\usepackage{enumitem}
\usepackage{cleveref}
\begin{document}
\begin{enumerate}[label=(\roman*)]
\item\label{A} First
\item\label{B} Second
\item\label{C} Want to have (ii') here.
\item\label{D} Fourth
\end{enumerate}
Let's reference them: \ref{A}, \ref{B}, \ref{C} (want to have (ii') also here), and \ref{D} (want to have ``(iii)'' here).\\
Let's test cleveref: \cref{A}, \cref{B}, \cref{C} (want to have ``item (ii')'' here), \cref{D} (want to have ``item (iii)'' here),\\
\labelcref{A}, \labelcref{B}, \labelcref{C} (want to have ``(ii')'' here), and \labelcref{D} (want to have ``(iii)'' here), 
\end{document}

与此相反,我希望

(我先来

(二)第二

(ii') (ii)的另一个版本。

(三)第四

让我们参考它们:(i)、(ii)、(ii')、(iii)。

让我们测试一下 cleveref:项目 (i)、项目 (ii)、项目 (ii')、项目 (iii)、(i)、(ii)、(ii') 和 (iii)。

如何在 LaTeX 中做到这一点而不对标准宏引入全局更改?我们仍然可以引入我们自己的新宏和对标准宏的局部更改。此外,对于 cleveref 版本,我仍然希望分别引用带有\ref{A}\ref{B}\ref{C}\ref{D},不带有(\ref{A})(\ref{B})(\ref{C})、的所有项目。(\ref{D})

我试过

\documentclass{article}
\usepackage{textcomp}
\usepackage{enumitem}
\usepackage{cleveref}
\makeatletter
\newcommand\itemprime{%
  \item[(\roman{enumi}\textquotesingle)]%
  \def\@currentlabel{(\roman{enumi}\textquotesingle)}%
  \def\cref@currentlabel{(\roman{enumi}\textquotesingle)}%
}
\makeatother
\crefname{itemprime}{item}{item}
\begin{document}
\begin{enumerate}[label=(\roman*)]
\item\label{A} First
\item\label{B} Second
\itemprime\label{C} Want to have (ii') here.
\item\label{D} Fourth
\end{enumerate}
Let's reference them: \ref{A}, \ref{B}, \ref{C} (want to have (ii') also here), and \ref{D} (want to have ``(iii)'' here).\\
Let's test cleveref: \cref{A}, \cref{B}, \cref{C} (want to have ``item (ii')'' here), \cref{D} (want to have ``item (iii)'' here),\\
\labelcref{A}, \labelcref{B}, \labelcref{C} (want to have ``(ii')'' here), and \labelcref{D} (want to have ``(iii)'' here), 
\end{document}

但结果并不令人鼓舞。

答案1

的格式\cref@currentlabel与 有很大不同\@currentlabel

您必须\itemprime按以下方式定义才能实现您想要的目标:

\newcommand\itemprime{%
  \item[(\roman{enumi}\textquotesingle)]%
  \def\@currentlabel{(\roman{enumi}\textquotesingle)}%
  \protected@edef\cref@currentlabel{%
    [\@tempa][\arabic{enumi}'][\cref@result](\roman{enumi}\textquotesingle)}%
}

另请注意

\crefname{itemprime}{item}{item}

itemprime由于没有定义计数器,因此不执行任何操作,而且由于您正在使用enumi它,所以也不需要它\itemprime

梅威瑟:

\documentclass{article}
\usepackage{textcomp}
\usepackage{enumitem}
\usepackage{cleveref}
\makeatletter
\newcommand\itemprime{%
  \item[(\roman{enumi}\textquotesingle)]%
  \def\@currentlabel{(\roman{enumi}\textquotesingle)}%
  \protected@edef\cref@currentlabel{%
    [\@tempa][\arabic{enumi}'][\cref@result](\roman{enumi}\textquotesingle)}%
}
\makeatother
%\crefname{itemprime}{item}{item}
\begin{document}
\begin{enumerate}[label=(\roman*)]
\item\label{A} First
\item\label{B} Second
\itemprime\label{C} Want to have (ii') here.
\item\label{D} Fourth
\end{enumerate}

Let's reference them: \ref{A}, \ref{B}, \ref{C} , and \ref{D}.

Let's test cleveref: \cref{A}, \cref{B}, \cref{C}, and \cref{D},

\labelcref{A}, \labelcref{B}, \labelcref{C}, and \labelcref{D}.
\end{document} 

输出:

在此处输入图片描述 为了完整起见,这是该.aux文件的内容:

\relax
\newlabel{A}{{{{(i)}}}{1}}
\newlabel{A@cref}{{[enumi][1][]{{(i)}}}{1}}
\newlabel{B}{{{{(ii)}}}{1}}
\newlabel{B@cref}{{[enumi][2][]{{(ii)}}}{1}}
\newlabel{C}{{(ii\textquotesingle )}{1}}
\newlabel{C@cref}{{[enumi][2'][](ii\textquotesingle )}{1}}
\newlabel{D}{{{{(iii)}}}{1}}
\newlabel{D@cref}{{[enumi][3][]{{(iii)}}}{1}}

编辑(回应 OP 的评论)

是的,借助宏是可以的。将和之间\@ifpackageloaded的代码替换为\makeatletter\makeatother

\makeatletter
\newcommand{\setclevereflabel}{\relax}
\@ifpackageloaded{cleveref}{%
  \renewcommand{\setclevereflabel}{%
    \protected@edef\cref@currentlabel{%
      [\@tempa][\arabic{enumi}'][\cref@result](\roman{enumi}\textquotesingle)}%
  }%
}{}
\newcommand\itemprime{%
  \item[(\roman{enumi}\textquotesingle)]%
  \def\@currentlabel{(\roman{enumi}\textquotesingle)}%
  \setclevereflabel%
}
\makeatother

MWE(按原样尝试并取消注释注释行):

\documentclass{article}
\usepackage{textcomp}
\usepackage{enumitem}
%\usepackage{cleveref}

\makeatletter
\newcommand{\setclevereflabel}{\relax}
\@ifpackageloaded{cleveref}{%
  \renewcommand{\setclevereflabel}{%
    \protected@edef\cref@currentlabel{%
      [\@tempa][\arabic{enumi}'][\cref@result](\roman{enumi}\textquotesingle)}%
  }%
}{}
\newcommand\itemprime{%
  \item[(\roman{enumi}\textquotesingle)]%
  \def\@currentlabel{(\roman{enumi}\textquotesingle)}%
  \setclevereflabel%
}
\makeatother

\begin{document}
\begin{enumerate}[label=(\roman*)]
\item\label{A} First
\item\label{B} Second
\itemprime\label{C} Want to have (ii') here.
\item\label{D} Fourth
\end{enumerate}

Let's reference them: \ref{A}, \ref{B}, \ref{C} , and \ref{D}.

%Let's test cleveref: \cref{A}, \cref{B}, \cref{C}, and \cref{D},

%\labelcref{A}, \labelcref{B}, \labelcref{C}, and \labelcref{D}.
\end{document} 

相关内容