Is there a way to keep the enumeration list with (a), (b), etc., and have references provide the complete context like 1.1.1(a)?
The section and sub-section references display as I’d like with 1.1 and 1.1.1 and the name-references works as well, “First” and “And..”. The enumerated item reference shows as 28 but I'd like 1.1.1(ab). And the enumerated item name-reference is wrong (“Also..”), though perhaps that’s intentional. So, the enumerated alpha item reference has two issues: it doesn’t include it’s context; and, it doesn’t honor the enumeration alpha display characteristics.
For my use, a custom command for the references is fine but the command hopefully won't require both the subsection and the item labels, e.g., instead of writing the verbose and error-prone:
\myuglyitemref{subsec:first-and}{itm:faab}
is there some way to define a reference so I can write:
\myawesomeitemref{itm:faab}
which displays 1.1.1(ab)?
\documentclass{report}
\usepackage{alphalph}
\usepackage{enumitem}
\usepackage{nameref}
\makeatletter
\def\enumalphalphcnt#1{\expandafter\@enumalphalphcnt\csname c@#1\endcsname}
\def\@enumalphalphcnt#1{\alphalph{#1}}
\makeatother
\AddEnumerateCounter{\enumalphalphcnt}{\@enumalphalphcnt}{aa}
\renewcommand{\labelenumi}{(\enumalphalphcnt{enumi})}
% my (ugly) item reference
\newcommand{\myuglyitemref}[2]{\ref{#1}\labelenumi}
\begin{document}
\chapter{SOMETHING}The chapter.
\section{First}\label{sec:first}
Section items show with (ab) but referenced with 1.1(ab)
\begin{enumerate}\setcounter{enumi}{27}
\item {First 28} \label{itm:fab} 28th element
\end{enumerate}
\subsection{And...}\label{subsec:first-and}
Subsection items show with (a) but referenced with 1.1.1(a)
\begin{enumerate}\setcounter{enumi}{27}
\item {And 28} \label{itm:faab} 28th element
\end{enumerate}
Correct: \ref{sec:first} and \ref{subsec:first-and}
Correct: ``\nameref{sec:first}'' and ``\nameref{subsec:first-and}''
Incorrect: \ref{itm:fab} and \ref{itm:faab} - should be 1.1(ab) and 1.1.1(ab)
Incorrect: ``\nameref{itm:faab}''
Ugly: \myuglyitemref{subsec:first-and}{itm:faab}
Best Answer
My answer addresses only the cross-referencing of enumerated items, where the appearance of the cross-referenced "numbers" depends on whether the items occur at the section level or the subsection level. (Aside: This site "works" best if postings contain only one major question at a time. That's why I'm not even trying to address the other major question you've raised, viz., how to use
\nameref
on the "titles" of enumerated items.)The solution works by modifying the low-level LaTeX macros
\theenumi
,\labelenumi
, and\p@enumi
. Observe the use of an\ifnum
conditional in the statement that modifies the\p@enumi
macro.In the example below, the
hyperref
package is loaded merley to highlight which parts of the typeset text are the actual cross-references generated by\ref
instructions.