为枚举项设置自定义显示名称,然后引用它们

为枚举项设置自定义显示名称,然后引用它们

在某个enumerate环境中,我想要:

  • 为项目提供自定义显示名称,
  • \label这些项目,
  • \ref这些项目,并让其显示显示名称。

我发现我可以通过将其作为可选参数传递来修改显示名称\item。但是,更改后\ref不再打印任何内容。

\documentclass{article}
\usepackage{enumerate}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=(\alph*)]
\item \label{Orange} It's orange.
\item \label{Round} It's round.
\item \label{Great} It's great.
\end{enumerate}
By properties \ref{Orange}, \ref{Round}, and \ref{Great} the item is a fruit.

\begin{enumerate}[label=Orangeaaa, leftmargin=*]
\item[(Orange)] \label{OrangeB} It's orange.
\item[(Round)] \label{RoundB} It's round.
\item[(Great)] \label{GreatB} It's great.
\end{enumerate}
By properties \ref{OrangeB}, \ref{RoundB}, and \ref{GreatB} the item is a fruit.
    
\end{document}

结果

我想读这个By properties (Orange), (Round), and (Great), the item is a fruit.

如何实现这一点?

答案1

下面的示例提供了\setitem{<label>}设置\item[<label>]和更新- s\@currentlabel所需的宏。\label

在此处输入图片描述

\documentclass{article}

\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=(\alph*)]
  \item \label{Orange} It's orange.
  \item \label{Round} It's round.
  \item \label{Great} It's great.
\end{enumerate}
By properties \ref{Orange}, \ref{Round}, and \ref{Great} the item is a fruit.

\makeatletter
\newcommand{\setitem}[1]{\item[#1]\def\@currentlabel{#1}}
\makeatother

\begin{enumerate}[label=Orangeaaa, leftmargin=*]
  \setitem{(Orange)} \label{OrangeB} It's orange.
  \setitem{(Round)} \label{RoundB} It's round.
  \setitem{(Great)} \label{GreatB} It's great.
\end{enumerate}
By properties \ref{OrangeB}, \ref{RoundB}, and \ref{GreatB} the item is a fruit.
    
\end{document}

相关内容