![为枚举项设置自定义显示名称,然后引用它们](https://linux22.com/image/461711/%E4%B8%BA%E6%9E%9A%E4%B8%BE%E9%A1%B9%E8%AE%BE%E7%BD%AE%E8%87%AA%E5%AE%9A%E4%B9%89%E6%98%BE%E7%A4%BA%E5%90%8D%E7%A7%B0%EF%BC%8C%E7%84%B6%E5%90%8E%E5%BC%95%E7%94%A8%E5%AE%83%E4%BB%AC.png)
在某个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}