2

I have a multilevel list. I would like to be able to sometimes refer to a level two item as 1a, and other times as just a. How can I do this?

MWE:

\documentclass{article}
\usepackage{enumitem}
\begin{document}

Here are some questions:

\begin{enumerate}
\item \label{Q:WhatIsBlue} What is blue?
\begin{enumerate}
\item \label{Q:IsBlueRed} Is blue red?
\item \label{Q:IsBlueYellow} Is blue yellow?
\end{enumerate}
\end{enumerate}

Question~\ref{Q:IsBlueRed} is a subquestion of question~\ref{Q:WhatIsBlue}. Also, question~\ref{Q:WhatIsBlue} has two parts, \ref{Q:IsBlueRed} and \ref{Q:IsBlueYellow}. It is good that I can refer to question~\ref{Q:IsBlueRed} as \ref{Q:IsBlueRed}, but sometimes I will need to refer to it as just ``a'', not \ref{Q:IsBlueRed}. How can I do this?


\end{document}

enter image description here

I would like to have a way of referring to the crossed out items as just a and b, while also preserving the ability to refer to 1a and 1b.

If possible, I do not want to use \ref{Q:WhatIsBlue}\ref{Q:IsBlueRed} because if the second level question "Is blue red?" is moved to another first level question, the reference will no longer makes sense. I would like to be able to move subquestions around without references breaking.

1 Answer 1

2

You can try zref. It allows you to create additional properties to the label, where you can store just the part of the enumerate subcounter you want, and then refer to it.

\documentclass{article}
\usepackage{enumitem}
\usepackage{zref-user}
\makeatletter
\zref@newprop{enumii}{\alph{enumii}}
\AddToHook{env/enumerate/begin}{%
  \zref@iflistcontainsprop{main}{enumii}{}{%
    \zref@localaddprop{main}{enumii}%
  }%
}
\makeatother

\begin{document}

Here are some questions:

\begin{enumerate}
\item \zlabel{Q:WhatIsBlue} What is blue?
\begin{enumerate}
\item \zlabel{Q:IsBlueRed} Is blue red?
\item \zlabel{Q:IsBlueYellow} Is blue yellow?
\end{enumerate}
\end{enumerate}

Question~\zref{Q:IsBlueRed} is a subquestion of
question~\zref{Q:WhatIsBlue}. Also, question~\zref{Q:WhatIsBlue} has two
parts, \zref[enumii]{Q:IsBlueRed} and \zref[enumii]{Q:IsBlueYellow}. It is
good that I can refer to question~\zref{Q:IsBlueRed} as \zref{Q:IsBlueRed},
but sometimes I will need to refer to it as just
``\zref[enumii]{Q:IsBlueRed}'', not \zref{Q:IsBlueRed}. How can I do this?

\end{document}

enter image description here

You must log in to answer this question.

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