我在课堂上创建了一个自定义列表环境book
。列表的标签按我想要的方式生成,但引用项目时,它们没有正确标记。这是代码。有人知道如何解决这个问题吗?
\documentclass[11pt]{book}
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\usepackage{amsfonts,fancyhdr,amsmath,amsthm,amssymb,graphicx}
\usepackage{amscd}
\usepackage[neverdecrease]{paralist}
\usepackage{amsmath,amssymb,latexsym,graphicx}
\usepackage{pstricks}
\renewcommand{\theenumi} {\arabic{enumi}}
\renewcommand{\labelenumi}{\theenumi}
\renewcommand{\theenumii} {\alph{enumii}}
\renewcommand{\labelenumii}{\theenumii}
\renewcommand{\labelenumii}{(\theenumii)}
%\renewcommand{\p@enumi}{\theenumi--}
\newcommand{\mynonsense}
{
\vspace{1cm}\begin{center}{\scshape\large Nonsense}\end{center}\vspace{2pt}\noindent
}
\setdefaultleftmargin{4em}{3em}{1.87em}{1.7em}{1em}{1em}
\newenvironment{mylist}
{\pagestyle{plain}
\setdefaultleftmargin{2em}{3em}{1.87em}{1.7em}{1em}{1em}
\setlength{\topsep}{3.mm}
\setdefaultenum{1$\;$}{a$\;$}{i$\;$}{A$\;$}
\bigskip
\begin{compactenum}
\renewcommand{\labelenumi}{\thechapter-\arabic{enumi}}
\renewcommand{\labelenumii}{\thechapter-\arabic{enumi}.\arabic{enumii}}
\setlength{\itemsep}{3.mm}
\setlength{\topsep}{3.mm}}
{\end{compactenum}
\bigskip
}
\begin{document}
\chapter{Chapter 1}
\mynonsense % command which produces header
\begin{mylist}
\item \label{1} item 1-1
\item \label{2} item 1-2
\begin{mylist}
\item \label{2a1} item 1-2.1
\item \label{2a2} item 1-2.2
\end{mylist}
\item \label{3} item 1-3
\begin{compactenum}[(a)]
\item \label{a} item 1-3a
\item \label{b} item 1-3b
\end{compactenum}
\end{mylist}
Labels print out as \ref{1}, \ref{2}, \ref{2a1}, \ref{2a2}, \ref{3}, \ref{a},
\ref {b}, which is wrong. Correct is (1-1), (1-2), (1-2.1), (1-2.2) (1-3),
(1-3a), (1-3b).
\end{document}
答案1
\labelenumi
和类似命令只会改变标签的显示方式。为了更改计数器的实际表示(由\label
和\ref
命令引用),您需要在自定义环境中分别将\labelenumi
和替换\labelenumii
为\theenumi
和。\theenumii
只需在您的示例文本中立即更改行后的内容\begin{compactenum}
即可。