2

I have created a customized list environment in the book class. The labels for the list are produced the way I want, but when items are referenced, they are not labeled correctly. Here is the code. Does anyone know how to solve this problem?

\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
    Welcome to TeX.SX! Did you have a look at the enumitem package that's more powerful than paralist? – egreg Nov 25 '13 at 23:10
3

\labelenumi and similars only change how the label is presented. In order to change the actual representation of the counter (which is referenced by the \label and \ref commands), you need to replace your \labelenumi and \labelenumii with \theenumi and \theenumii respectively in your custom environment.

Just changing those right after the \begin{compactenum} line did it for me in your example text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.