# Referencing in custom label enumerate environment

I want to reference the item number of a two-level enumerate environment. The code below gives the correct item numbering, but when I reference it in the text, something goes wrong - see below the code. It should say "I prefer option 2.1" of course. Thanks for any help.

\documentclass[11pt]{article}

\renewcommand{\theenumii}{\theenumi.\arabic{enumii}}
\renewcommand{\labelenumii}{\theenumii}

\begin{document}

\begin{enumerate}

\item Hallo
\item Hi

\begin{enumerate}

\item \label{item-one} Good By
\item \label{item-two} Have a nice time

\end{enumerate}
\end{enumerate}

I prefer option \ref{item-one}

\end{document}


I recommend using the enumitem package as it makes things like this really easy. For your example, you can produce

using the code:

\documentclass[11pt]{article}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}

\item hallo
\item hi

\begin{enumerate}[label=\arabic{enumi}.\arabic*]

\item \label{item-one} good by
\item \label{item-two} have a nice time

\end{enumerate}
\end{enumerate}

I prefer option \ref{item-one}

\end{document}


There are many other bells and whistles provided by enumitem for customising enumerate, itemize and description environments, including defining your own variants of each of these environments. See the manual for details.

\renewcommand{\theenumii}{\theenumi.\arabic{enumii}}

\renewcommand{\theenumii}{\arabic{enumii}}