嵌套枚举项在交叉引用时缺少一些句点

嵌套枚举项在交叉引用时缺少一些句点

我正在编写一本规则手册,需要引用其中的条款和子条款。

当我有一个嵌套的枚举项到 5.4.2.3 级别时,交叉引用显示为 5.4.2.23。

\documentclass[a4paper,12pt]{report}

\usepackage{enumerate}
\usepackage{hyperref}

\begin{document}

\chapter{Rulebook}
\section{Footwear Rules}
\begin{enumerate}[\thesection .1.]
\item No running.\label{itm:running}
   \begin{enumerate}[\thesection.\ref{itm:running}.1.]
   \item Running is punishable by death.
   \end{enumerate}

\item Each person shall be responsible for: \label{itm:duty}
  \begin{enumerate}[\thesection.\ref{itm:duty}.1.]
  \item Clean shoes.
  \item Clean socks.
  \item Tied laces.\label{itm:socks}
  \end{enumerate}

\item Applications for new shoes shall be sent to the Dean.\label{itm:new}
  \begin{enumerate}[\thesection.\ref{itm:new}.1.]
  \item Applications shall:
   \begin{itemize}
   \item Indicate the name of the applicants;
   \item Indicate any instances when the applicant has broken Rule \thesection.\ref{itm:duty}.\ref{itm:socks}.
   %The above item contains the offending \ref
   \end{itemize}
  \end{enumerate}

\end{enumerate}

\end{document}

此代码给出以下输出: 在此处输入图片描述

我该怎么做才能使参考显示为“规则 1.1.2.3”?

我在终端中编译

$ latex file.tex
$ latex file.tex
$ dvips file.dvi

答案1

这是一个仅使用低级 LaTeX 宏而不使用任何软件包的解决方案。这些宏称为\theenumi\labelenumi\theenumii\labelenumii\p@enumii

像对待任何其他 (LaTeX) 对象一样对枚举项使用\label和。当然,如果您愿意,您仍然可以加载包。\refenumerate

在此处输入图片描述

\documentclass[a4paper,12pt]{report}

%%\usepackage{enumerate}  %% not needed
\renewcommand\theenumi{\thesection.\arabic{enumi}}
\renewcommand\labelenumi{\theenumi.}
\renewcommand\theenumii{\theenumi.\arabic{enumii}}
\renewcommand\labelenumii{\theenumii.}
\makeatletter
\renewcommand\p@enumii{}
\makeatother

\usepackage{hyperref}

\begin{document}

\chapter{Rulebook}
\section{Footwear Rules}
\begin{enumerate}%%[\thesection .1.]  %% not needed
\item No running.\label{itm:running}
   \begin{enumerate}
   \item Running is punishable by death.
   \end{enumerate}

\item Each person shall be responsible for: \label{itm:duty}
  \begin{enumerate}%%[\thesection.\ref{itm:duty}.1.] %% not needed
  \item Clean shoes.
  \item Clean socks.
  \item Tied laces.\label{itm:socks}
  \end{enumerate}

\item Applications for new shoes shall be sent to the Dean.\label{itm:new}
  \begin{enumerate}%%[\thesection.\ref{itm:new}.1.] %% not needed
  \item Applications shall:
   \begin{itemize}
   \item Indicate the name of the applicants;
   \item Indicate any instances when the applicant has broken Rule \ref{itm:socks}.
   %%The above item no longer contains an offending \ref
   \end{itemize}
  \end{enumerate}

\end{enumerate}
\end{document}

附录:加载chngcntr包并执行以下指令可以达到同样的效果:

\usepackage{chngcntr}
\counterwithin{enumi}{section}
\counterwithin{enumii}{enumi}
\renewcommand\labelenumi{\theenumi.}   % add a "dot" after '\theenumi'
\renewcommand\labelenumii{\theenumii.} % add a "dot" after '\theenumii'
\makeatletter
\renewcommand\p@enumii{} % remove the "prefix" from `enumii` in cross-references
\makeatother

相关内容