Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to have a list like this:

a) Aha
b) Bla
Look at a) and b).

I write some code like this

\documentclass{article}

\renewcommand{\theenumi}{\alph{enumi}}
\renewcommand{\labelenumi}{\theenumi)}
%\makeatletter
%\renewcommand{\p@enumi}{\theenumi)}
%\makeatother
\usepackage{hyperref}
\begin{document}
\begin{enumerate}
  \item \label{item:1} Aha
  \item \label{item:2} Bla
\end{enumerate}
Look at~\ref{item:1} and~\ref{item:2}.
\end{document}

It works fine except the printed ref is not correct. I have tried the commented code, however it does not work.

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

The enumitem package provides this functionality by default - specifying different label and ref components (if needed) for list items. Here's your minimal example moulded into an enumitem interface:

enter image description here

\documentclass{article}
\usepackage{enumitem}% http://ctan.org/pkg/enumitem
\usepackage{hyperref}% http://ctan.org/pkg/enumitem
\begin{document}
\begin{enumerate}[label={\alph*)},ref={\alph*)}]
  \item \label{item:1} Aha
  \item \label{item:2} Bla
\end{enumerate}
Look at~\ref{item:1} and~\ref{item:2}.
\end{document}​

The label key specifies how the enumeration will print within the list, while ref indicates the style of printing when using \ref.

Global settings is also possible via

\setlist[enumerate,1]{label={\alph*)},ref={\alph*)}}

which sets key-value pairs for enumerate at level 1. See the enumitem documentation for more details and setting possibilities.

share|improve this answer
2  
+1: worth mentioning \setlist for global changes? –  cmhughes Mar 6 '12 at 20:52
    
@cmhughes: Thanks for the suggestion; I've added it. –  Werner Mar 6 '12 at 20:56
add comment

Your code works if the label key and the reference key are equal ;-) and the bracket is set inside the macro theenumi

\documentclass{article}

\renewcommand{\theenumi}{\alph{enumi})}
\renewcommand{\labelenumi}{\theenumi}
\makeatletter
%\renewcommand{\p@enumi}{}
\makeatother
\usepackage{hyperref}
\begin{document}
\begin{enumerate}
  \item \label{item:1} Aha
  \item \label{item:2} Bla
\end{enumerate}
Look at~\ref{item:1} and~\ref{item:2}.
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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