我有类似的东西:
\section{a section name}
\subsection{a subsection name}
\begin{enumerate}
\item\label{itm:first} Item one
\item Item two
\item Item three
\end{enumerate}
I am saying something else about \ref{itm:first}
输出的底行如下所示:I am saying something else about 1
。有没有办法在列表项的引用中包含列表项所在的部分编号?这看起来像I am saying something else about 1.1.1
答案1
如果我理解正确的话,您希望枚举项按正常方式编号,但引用中的编号采用小节编号。这里有两个命令可供您使用,\theenumi
和\labelenumi
。它们通常(如文章中所示)定义如下:
\newcommand\theenumi{\arabic{enumi}} %% Format for references
\newcommand\labelenumi{\theenumi.}. %% Printed by \item (add '.')
要获得参考文献的特殊格式,您可以这样做
\renewcommand\labelenumi{\arabic{enumi}.}
\renewcommand\theenumi{\thesubsection.\arabic{enumi}}%% references with subsection numbering
但即使可能,我也不太推荐这样做。参考文献是为了让读者在文中查找特定位置,在\item
参考文献中使用不同的格式会造成混淆。
另一种方法是将额外的编号添加到\item
和参考文献中
\renewcommand\theenumi{\thesubsection.\arabic{enumi}}
然后,与正常定义\labelenumi
相同,只是使用一个附加句点。
我更喜欢的第三种选择是在文本中指定您想要的枚举列表,例如in Subsection~\ref{sec:Mysubsection}
。
所有上述版本均在下面的一个文件中给出。
\documentclass{article}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand\labelenumi{\arabic{enumi}.}
\renewcommand\theenumi{\thesubsection.\arabic{enumi}}%% references with subsection numbering
\section{a section name}
\subsection{a subsection name}
\begin{enumerate}
\item\label{itm:first} Item one
\item Item two
\item Item three
\end{enumerate}
I am saying something else about item \ref{itm:first}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand\theenumi{\arabic{enumi}}%% Back to normal
\renewcommand\labelenumi{\theenumi.}%% Back to normal
\renewcommand\theenumi{\thesubsection.\arabic{enumi}}%% Add subsection number to item
\section{a section name}
\subsection{a subsection name}
\begin{enumerate}
\item Item one
\item \label{itm:second}Item two
\item Item three
\end{enumerate}
I am saying something else about item \ref{itm:second}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand\theenumi{\arabic{enumi}}%% Back to normal
\section{a section name}
\label{sec:Mysection}
\subsection{a subsection name}
\label{sec:Mysubsection}
\begin{enumerate}
\item Item one
\item Item two
\item \label{itm:third}Item three
\end{enumerate}
I am saying something else about item \ref{itm:third} in Subsection~\ref{sec:Mysubsection}.
\end{document}