我有一份包含章节和尾注以及目录 (TOC) 的文档。为了不为最后一章 (尾声) 生成编号,我在代码中使用 \chapter*{Epilogue},然后使用命令 \addcontentsline{toc} 手动在目录中添加一行。问题是,目录中“注释”部分的页码似乎是错误的:它等于尾声的页码。
如何改变这个数字(将其增加 2)?
这是代码(大部分是从我之前的问题的答案中借用的尾注中的章节编号):
\documentclass[12pt]{book}
\usepackage{endnotes,chngcntr}
\counterwithin*{endnote}{chapter} % Reset endnote numbering every new chapter
\makeatletter
\renewcommand\enoteheading{%
\setcounter{secnumdepth}{-2}
\chapter*{\notesname\markboth{NOTES}{}}
\mbox{}\par\vskip-\baselineskip
\let\@afterindentfalse\@afterindenttrue
}
\makeatother
\usepackage{xparse}
\let\latexchapter\chapter
\RenewDocumentCommand{\chapter}{som}{%
\IfBooleanTF{#1}
{\latexchapter*{#3}}
{\IfNoValueTF{#2}
{\latexchapter{#3}}
{\latexchapter[#2]{#3}}%
\addtoendnotes{%
\noexpand\enotedivision{\noexpand\subsection}
{\chaptername\ \thechapter. \unexpanded{#3}}}%
}%
}
\makeatletter
\def\enotedivision#1#2{\@ifnextchar\enotedivision{}{#1{#2}}}
\makeatletter
\begin{document}
\setcounter{tocdepth}{1}
\tableofcontents
\chapter*{Preface\markboth{PREFACE}{}}
\addcontentsline{toc}{chapter}{Preface}
This is the Prologue. There are no endnotes here.
\chapter{Amazing Story}
As I am describing this story, I make a note which should appear at
the end.\endnote{This the first endnote.} And then I make the second
note.\endnote{This is the second note.}
\chapter{Another Amazing Story}
In this chapter, there are no endnotes. So it should not appear in the
"Notes" at the end.
\chapter{Yet Another Amazing Story}
In this chapter, I have some notes again, which I want to go to the
end.\endnote{This note should appear at the end, under the heading
"Chapter 3. Yet Another Amazing Story", with the counter reset to 1,
since this is the first endnote of this chapter.}
\chapter*{Epilogue\markboth{EPILOGUE}{}}
\addcontentsline{toc}{chapter}{Epilogue}
This is the Epilogue. No endnotes here.
\addtoendnotes{\unexpanded{\enotedivision{}{}}}
\addcontentsline{toc}{chapter}{Notes}
\theendnotes
\end{document}
答案1
放在\cleardoublepage
之前(如果您使用\addcontentsline{toc}{chapter}{Notes}
也一样)。\phantomsection
hyperref
\cleardoublepage
%\phantomsection % if you're using hyperref, uncomment this line
\addcontentsline{toc}{chapter}{Preface}
\chapter*{Preface}
\markboth{PREFACE}{}
为了分配特定的页码,最好说
\cleardoublepage
\setcounter{page}{42}
%\phantomsection % if you're using hyperref, uncomment this line
\addcontentsline{toc}{chapter}{Preface}
\chapter*{Preface}
\markboth{PREFACE}{}