使用列表命令进行交叉引用时出现的问题

使用列表命令进行交叉引用时出现的问题

我在使用 list 命令时遇到了问题。我需要生成具有特定编号系统的列表,然后在不同部分交叉引用它们。通过使用 list 命令,我能够创建具有正确编号系统的列表。但是,当我使用 \ref 命令引用它们时,它只会打印条目的阿拉伯数字等价物,而不是我使用的编号系统。有什么方法可以解决这个问题,以便我可以插入正确的交叉引用。

为了说明我的问题,我为此编写了一个简短的代码,也说明了我的问题。


\documentclass[12pts,a4paper]{report}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{color}

\newcounter{sections}
\newcounter{sub-section}
\newcounter{clause}
\newcounter{sub-clause}
%this is the counter command  

\title{Problem with cross-referencing using list command}

\author{Shubho Roy}

\begin{document}
\maketitle


\begin{list}{(\arabic{sub-section})}{\usecounter{sub-section}}
\item This is some text in sub-section which is using Arabic
  numerals. \label{sub-sec:arabic_numerals}
\begin{list}{(\alph{clause})}{\usecounter{clause}}
\item This is a clause which is using alphabetical numbering
\label{clause:alphabetical}
\begin{list}{(\roman{sub-clause})}{\usecounter{sub-clause}}
\item This is a sub-clause using roman numbering. \label{sub-clause:roman_numerals}
\end{list}    
\end{list}    
\end{list}


\begin{itemize}
\item If I refer to the sub-section using the ref command I get a correct
reference like this: \ref{sub-sec:arabic_numerals}

\item However when I refer to the clause list which is a nested list and
uses alphabetical numbering I still get Arabic numbering as reference:
\ref{clause:alphabetical}. I would like this to be (a)

\item The same problem is available in the case of sub-clause list where I
should get roman numerals but I still get the Arabic numeral:
\ref{sub-clause:roman_numerals}. I would like this to be (i)

\end{itemize}

\end{document}

当我使用标签引用文档的不同部分时出现的问题。

hyperref命令将其发送到正确的链接,但打印的编号始终为阿拉伯数字,而我为此使用了其他编号系统。有任何帮助吗?

答案1

您必须重新定义\the<counter>命令。此外,您还应避免在计数器名称中使用非字母,这会使此类重新定义变得困难。请使用subclause而不是sub-clause:

\renewcommand\theclause{(\alph{clause})}
\renewcommand\thesubclause{(\roman{subclause})}

答案2

enumitem包非常适合这种设置。使用 创建新类型的列表,例如\newlist{clause}{enumerate}{4};这是一个基于通常enumerate环境的列表,但调用clause并自动获取与其关联的新计数器。您可以通过对应的命令的位置clause来自定义标签的格式。将它们放在一起,您的示例将变为:\setlist[clause]{label=(\alph*)}\alph*\alph

\documentclass[12pt,a4paper]{report}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{color}
\usepackage{enumitem}

\newlist{sub-section}{enumerate}{5}
\setlist[sub-section]{label=(\arabic*)}

\newlist{clause}{enumerate}{4}
\setlist[clause]{label=(\alph*)}

\newlist{sub-clause}{enumerate}{3}
\setlist[sub-clause]{label=(\roman*)}

\title{Problem with cross-referencing using list command}

\author{Shubho Roy}

\begin{document}
\thispagestyle{empty}

\begin{sub-section}
\item This is some text in sub-section which is using Arabic
  numerals. \label{sub-sec:arabic_numerals}
\begin{clause}
\item This is a clause which is using alphabetical numbering
\label{clause:alphabetical}
\begin{sub-clause}
\item This is a sub-clause using roman numbering. \label{sub-clause:roman_numerals}
\end{sub-clause}    
\end{clause}    
\end{sub-section}

\begin{itemize}
\item If I refer to the sub-section using the ref command I get a correct
reference like this: \ref{sub-sec:arabic_numerals}

\item However when I refer to the clause list which is a nested list and
uses alphabetical numbering I still get Arabic numbering as reference:
\ref{clause:alphabetical}. I would like this to be (a)

\item The same problem is available in the case of sub-clause list where I
should get roman numerals but I still get the Arabic numeral:
\ref{sub-clause:roman_numerals}. I would like this to be (i)

\end{itemize}

\end{document}

示例输出

相关内容