I have the following code
\documentclass{scrreprt}
\usepackage{hyperref}
\begin{document}
\part{First Part}
\chapter{First Chapter}
\label{inner} Some text.
\part{Second Part}
\chapter{First Chapter}
\ref{inner}
\end{document}
that produces a reference 1
for the label inner
. How can I include the number of the part associated with the chapter in this reference, i.e. automatically create a cross-reference of the form I.1
?
Best Answer
The LaTeX kernel provides a nifty mechanism for "prefixing" material to cross-references to counters. For every counter variable defined somewhere via a
\newcounter
macro named, say,somecounter
, LaTeX automatically creates an auxilliary macro named\p@somecounter
, and the value of this macro is automatically prefixed to the result of a\ref
command that references the countersomecounter
.By default, these auxilliary prefixing macros are empty, but it's straightforward to modify them via
\renewcommand
instructions. For the case at hand, you could achieve your objective by adding the instructionsto the preamble, before loading
hyperref
. (The\makeatletter
and\makeatother
instructions are needed because the macro\p@chapter
contains the character@
which normally has category code "other".)