2

I´d like to obtain this enter image description here

How can you obtain letter instead a number in a cross reference (label/ref) in an enumitem (alph) ref/label?

Or any solution with the fantastic cleverref package?.

\documentclass[12pt]{exam}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{enumitem}
%\usepackage{hyperref}
%\hypersetup{colorlinks=true, urlcolor=blue}

%\usepackage[spanish]{cleveref}


\renewcommand{\labelenumi}{\alph{enumi}) }
\begin{document}

\begin{questions}

\question \label{sumas} Calculate:
\begin{enumerate} 
    \item \label{sumas-cinco} $5+5+5=$
    \item \label{sumas-nueve} $9+9+9+9=$
\end{enumerate}

You can see at \ref{mult} \ref{mult-cinco} a faster version of \ref{sumas} \ref{sumas-cinco}.


\question \label{mult} Calculate:
\begin{enumerate} 
    \item \label{mult-cinco} $3\cdot5=$
    \item \label{mult-nueve} $4\cdot9=$
\end{enumerate}

The exercise \ref{mult} is a faster versión of \ref{sumas}.

\end{questions}

\end{document} 

2 Answers 2

4

When using enumitem, don't redefine \labelenumi but use the user interface of the package, e.g., either:

\documentclass[12pt]{exam}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{enumitem}
%\usepackage{hyperref}
%\hypersetup{colorlinks=true, urlcolor=blue}

%\usepackage[spanish]{cleveref}

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

\begin{document}

\begin{questions}

\question \label{sumas} Calculate:
\begin{enumerate} 
    \item \label{sumas-cinco} $5+5+5=$
    \item \label{sumas-nueve} $9+9+9+9=$
\end{enumerate}

You can see at \ref{mult} \ref{mult-cinco} a faster version of \ref{sumas} \ref{sumas-cinco}.


\question \label{mult} Calculate:
\begin{enumerate} 
    \item \label{mult-cinco} $3\cdot5=$
    \item \label{mult-nueve} $4\cdot9=$
\end{enumerate}

The exercise \ref{mult} is a faster versión of \ref{sumas}.

\end{questions}

\end{document} 

2 a) 1 a)

or

\documentclass[12pt]{exam}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{enumitem}
%\usepackage{hyperref}
%\hypersetup{colorlinks=true, urlcolor=blue}

%\usepackage[spanish]{cleveref}

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

\begin{document}

\begin{questions}

\question \label{sumas} Calculate:
\begin{enumerate} 
    \item \label{sumas-cinco} $5+5+5=$
    \item \label{sumas-nueve} $9+9+9+9=$
\end{enumerate}

You can see at \ref{mult} \ref{mult-cinco} a faster version of \ref{sumas} \ref{sumas-cinco}.


\question \label{mult} Calculate:
\begin{enumerate} 
    \item \label{mult-cinco} $3\cdot5=$
    \item \label{mult-nueve} $4\cdot9=$
\end{enumerate}

The exercise \ref{mult} is a faster versión of \ref{sumas}.

\end{questions}

\end{document} 

2 a 1 a

See the enumitem user manual section 2 “Quick reference” for a similar example and section 3.1 “Label and cross references format” for the documentation of label=<commands> and ref=<commands>.

If references to the enumerations inside questions always should include the question number, you also can do something like:

\documentclass[12pt]{exam}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{enumitem}
%\usepackage{hyperref}
%\hypersetup{colorlinks=true, urlcolor=blue}

%\usepackage[spanish]{cleveref}

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

\begin{document}

\begin{questions}

\question \label{sumas} Calculate:
\begin{enumerate}[ref=\ref{sumas}\alph{*}]% use a label to show the question number
    \item \label{sumas-cinco} $5+5+5=$
    \item \label{sumas-nueve} $9+9+9+9=$
\end{enumerate}

You can see at \ref{mult-cinco} a faster version of \ref{sumas-cinco}.


\question \label{mult} Calculate:
\begin{enumerate}[ref=\thequestion\alph{*}]% use the question number directly
    \item \label{mult-cinco} $3\cdot5=$
    \item \label{mult-nueve} $4\cdot9=$
\end{enumerate}

The exercise \ref{mult} is a faster versión of \ref{sumas}.

\end{questions}

\end{document} 
5
  • I know about the bad code \renewcommand{\labelenumi}{\alph{enumi})} but not about the consecuencesof not obtaining the letter. Thank you.
    – Mika Ike
    Commented Dec 8, 2023 at 10:46
  • What a excelent answer!
    – Mika Ike
    Commented Dec 8, 2023 at 10:57
  • Are there a way to refer to exercise 2a) with an only label (without using a lbaelin the questioin and another in the enumerated list)?
    – Mika Ike
    Commented Dec 8, 2023 at 11:58
  • 1
    @MikaIke For a follow-up question you should ask a new question. However, see the last enumerate environment in the last example and add the wanted ) before the existing ]. If you want this for all enumerate environments, you can copy the option to a \setlist command in the document preamble.
    – cabohah
    Commented Dec 8, 2023 at 12:34
  • @MikaIke But before asking a follow-up question see, e.g., Defining a new list with enumitem that uses ref from surrounding environment
    – cabohah
    Commented Dec 8, 2023 at 12:42
2

You don't appear to be making use of the machinery of the enumitem package. If this impression is correctl, you need to redefine both \theenumi and \labelenumi yourself. For good measure, I'd also redefine the "prefix macro", \p@enumi, to simplify creating cross-refernences to level-1 items.

Observe that I would not include ) in the cross-reference "number".

enter image description here

\documentclass[12pt]{exam}
% \usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage{amsmath,amssymb}

\renewcommand{\labelenumi}{\alph{enumi})}
\renewcommand{\theenumi}{\alph{enumi}}
\makeatletter
\renewcommand{\p@enumi}{\thequestion}
\makeatother

\begin{document}

\begin{questions}
\question \label{sumas} Calculate:
\begin{enumerate} 
    \item \label{sumas-cinco} $5+5+5=$
    \item \label{sumas-nueve} $9+9+9+9=$
\end{enumerate}

\question \label{mult} Calculate:
\begin{enumerate} 
    \item \label{mult-cinco} $3\cdot5=$
    \item \label{mult-nueve} $4\cdot9=$
\end{enumerate}
\end{questions}

\noindent
You can see that \ref{mult-cinco} is faster than \ref{sumas-cinco}.

\noindent
Exercise \ref{mult} is a faster version of exercise \ref{sumas}.
\end{document} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .