默认情况下,documentclassbook
会连续对章节进行编号,而不管其是否分为各个部分,我想该\ref
命令的设计就是考虑到这一点,它会返回chapter
,section
并subsection
进行编号。该子句\@addtoreset{chapter}{part}
将导致每个部分的章节编号从 1 开始。有没有一种方法可以参数化\ref
以返回part
数字?
\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}
答案1
您可以重新定义\p@<counter>
以修改的输出,\ref
而无需更改其他地方的实际表示<counter>
。您可以尝试类似\renewcommand*{\p@section}{\thepart.}
或类似的操作。
\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}