I have multiple sections with enumerations in them. Given a reference, is it possible to get the section name it belongs to? And also the item number as well.

For example, given this code (with fictionary commands itemref and secref)

\section*{Example title}
    \item first one
    \item second one \label{ref:anchor}

\section*{Second title}
See item \itemref{ref:anchor} in section \secref{ref:anchor}.

the result would be

Example title
1. first one
2. second one

Second title
See item 2 in section "Example title".

I've found numerous ways to reference a section name, but as I understand it, the anchor must be the section itself, which wouldn't work in my case since I move items around in this document and I'd like it to be dynamic.

EDIT: I have a working solution with the enumitem package for the item number reference, so only the section name is missing.

  • 1
    With \section*, you're not going to have a section number.
    – TH.
    Jun 27 '17 at 6:54
  • @TH. That's intentional, since my section titles contain only numbers and it would be confusing. Hence my need to reference section with titles.
    – rubik
    Jun 27 '17 at 6:55

The zref package can help you out here.




\section*{Example title}
\item first one
\item second one\itemlabel{ref:anchor}

\section*{Second title}
See item~\itemref{ref:anchor} in Section \secref{ref:anchor}.

enter image description here

The one real difference to what you posted is I defined an \itemlabel macro which you need to use in place of \label.

  • 1
    Thanks a lot, the zref packages seems really powerful. Your solution is perfect!
    – rubik
    Jun 27 '17 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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