6

As a default documentclass book numbers chapters consecutively regardless of the division into parts, and I suppose the \ref command had been designed with this in mind, returning as it does chapter, section and subsection numbering. The clause \@addtoreset{chapter}{part} will cause chapters to be numbered starting with 1 for each part. Is there a way of paramatrizing \ref to return part numbers?

\documentclass{book}
% RN. 10 Nov 2018
%=======================
%\usepackage{hyperref}
\makeatletter
\@addtoreset{chapter}{part}
\makeatother
\begin{document}
\chapter*{Preface}
Referencing both sections produce identical numbering. It would be helpful to distinguish parts:\\
\ref{A1}, page \pageref{A1}\\
\ref{B1}, page \pageref{B1}\\
\part{FIRST}
\chapter{A}
\section{A1}\label{A1}
\part{SECOND}
\chapter{B}
\section{B1}\label{B1}
\end{document}
  • 4
    Something like \renewcommand*{\p@section}{\thepart.} (within \makeatletter...\makeatother)? – moewe Nov 10 '18 at 7:33
  • Works like a charm. How do I mark this as the answer? – Reinhard Neuwirth Nov 10 '18 at 9:01
  • 1
    You need to ping @moewe and ask that the text be re-posted as an answer, you can't mark comments as accepted answers. – David Carlisle Nov 10 '18 at 9:07
  • To complete @moewe 's answer I now use \renewcommand*{\p@chapter}{\thepart.}, \renewcommand*{\p@section}{\thepart.} and \renewcommand*{\p@subsection}{\thepart.}, sandwiched beween \makeatletter and \makeatother, and have \ref return numbering for all `part/chapter/section/subsection' as required. Please repost your comment as an answer so I can tick it off. – Reinhard Neuwirth Nov 10 '18 at 9:27
6

You can redefine \p@<counter> to modify the output of \ref without changing the actual representation of <counter> elsewhere. You might try something like \renewcommand*{\p@section}{\thepart.} or similar.

\documentclass{book}

\makeatletter
\@addtoreset{chapter}{part}
\renewcommand*{\p@chapter}{\thepart.}
\renewcommand*{\p@section}{\thepart.}
\renewcommand*{\p@subsection}{\thepart.}
\makeatother

\begin{document}
\chapter*{Preface}
Referencing both sections produce identical numbering. It would be helpful to distinguish parts:

\ref{A1}, page \pageref{A1}

\ref{B1}, page \pageref{B1}

\part{FIRST}
\chapter{A}
\section{A1}\label{A1}

\part{SECOND}
\chapter{B}
\section{B1}\label{B1}
\end{document}

the <code>\ref</code>s produce "I.1.1, page 5" and "II.1.1, page 9"

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.