考虑以下代码:
\documentclass[openany]{book}
\usepackage{color}
\usepackage{endnotes}
\let\footnote\endnote
\usepackage{chngcntr}
\counterwithin*{endnote}{chapter} % Reset endnote numbering everyv%new chapter
\usepackage{fancyhdr}
\let\latexchapter\chapter
\makeatletter %changes the catcode of @ to 11
\renewcommand\enoteheading{% changes being made here
\setcounter{secnumdepth}{-2}
\latexchapter*{\notesname\markboth{NOTES}{}}
\mbox{}\par\vskip-\baselineskip
\let\@afterindentfalse\@afterindenttrue
}
\makeatother %changes the catcode of @ back to 12
\usepackage{xparse}
\RenewDocumentCommand {\chapter}{som}{%
\IfBooleanTF{#1}
{\latexchapter*{#3}%
\setcounter{endnote}{0}%
\addtoendnotes{%
\noexpand\enotedivision{\noexpand\subsection}
{\unexpanded{#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
\usepackage{lettrine}
\setcounter{DefaultLines}{3}
\setlength{\DefaultFindent}{0em}
\setlength{\DefaultNindent}{.17em}
\renewcommand{\LettrineFontHook}{\usefont{U}{yinit}{m}{n}}
\renewcommand{\DefaultLoversize}{-0.67}
\definecolor{olivegreen}{cmyk}{0.64,0,0.95,0.40}
\begin{document}
\LARGE
%The Table of Contents
\renewcommand\contentsname{Table of Contents.}
\tableofcontents
\chapter*{INTRODUCTION}
\addcontentsline{toc}{chapter}{\textbf{INTRODUCTION.}}
\lettrine{\color{olivegreen}{T}}{\textbf{\color{olivegreen}his}} is the Introduction. Some words.\footnote{an endnote.} Some words.\footnote{an endnote.} Some words.
% PART I BEGINS HERE.
\chapter*{Chapter I}
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Chapter I.}}
\lettrine{\color{olivegreen}{T}}{\textbf{\color{olivegreen}his}} is Chapter I. of \textbf{PART I}. Some words.\footnote{an endnote.}Some words.\footnote{an endnote.}Some words.\footnote{an endnote.}
\chapter*{Chapter II}
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Chapter II.}}
\lettrine{\color{olivegreen}{T}}{\textbf{\color{olivegreen}his}} is Chapter II. Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}
% PART II BEGINS HERE.
\chapter*{Chapter I}
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Chapter I.}}
\lettrine{\color{olivegreen}{T}}{\textbf{\color{olivegreen}his}} is Chapter I. of \textbf{PART II}.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}
\chapter*{}
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Endnotes.}}
\renewcommand{\notesname}{Endnotes} % Renames `Notes' to `Endnotes'
\addtoendnotes{\unexpanded{\enotedivision{}{}}}
\theendnotes
\end{document}
生成目录:
如您所见,目录中的尾注部分列出了两次“第一章”——第一次是与文档第一部分相关的第一章;另一次是与第二部分相关的。我想插入第一部分(在第一章之前)和第二部分(位于第二章 I 之前)分隔符(留有适当的空间)放入目录中的尾注列表中,以清楚区分两组章节列表。
问题:我怎样才能实现这一目标?
谢谢。
答案1
我不喜欢\addcontentsline
你的代码中展示的“星号分段命令”策略。;-)
是因为它可能。
您可以采用\part
与修补 -command 相同的方式修补 -command \chapter
。
为了确保相应的\enotedivision
操作得到执行,请将例如附加\relax
到它们之后。
在您的代码中,在目录中创建小节级条目的机制被(ab?)用于显示目录的尾注列表中的章节级条目。
为了在目录的尾注列表中显示部分级条目,您可以类似地(ab?)使用在目录中创建部分级条目的机制。
我假设您不希望在这些条目中使用虚线来指向页码。
\l@section
因此我借用了和的代码\@dottedtocline
并创建了一个命令\l@myhandmadepart
,并让修补的\part
命令\addtoendnotes
也添加\addtocontents
指令以本地让其\l@section
等于\l@myhandmadepart
。
我不知道当使用 hyperref 时这是否也有效。
2022年1月26日编辑:
作为在评论中请求我修改了代码:
现在您有一个\endnotepart
采用与命令相同参数的命令\part
。
该命令\endnotepart
遵循三个\if...
开关:
\endnotepartDoDocumentPartDivisiontrue
/\endnotepartDoDocumentPartDivisionfalse
:
此开关切换是否也为您\endnotepart
执行\part
文档中的 -division。
如果此开关为真,\endnotepart
则也为您执行\part
。\endnotepartPartsInEndnotestrue
/\endnotepartPartsInEndnotesfalse
:
如果此开关为真,\endnotepart
则为尾注部分内的部分添加标题。\endnotepartPartsInEndnotesToclistingtrue
/\endnotepartPartsInEndnotesToclistingfalse
:
如果此开关为真,则\endnotepart
在目录中的尾注列表中添加部分条目。
我想这个开关对你来说是最有趣的。
\documentclass[openany]{book}
\usepackage{color}
\usepackage{endnotes}
\let\footnote\endnote
\usepackage{chngcntr}
\counterwithin*{endnote}{chapter} % Reset endnote numbering everyv%new chapter
\usepackage{fancyhdr}
%===============================================================================
% The \if-switches...
%===============================================================================
% Toggle whether \endnotepart shall do the \part-command as well:
\newif\ifendnotepartDoDocumentPartDivision
%\endnotepartDoDocumentPartDivisiontrue
\endnotepartDoDocumentPartDivisionfalse
%
% Toggle whether \endnotepart shall add headlines for parts within the
% endnotes-section as well:
\newif\ifendnotepartPartsInEndnotes
%\endnotepartPartsInEndnotestrue
\endnotepartPartsInEndnotesfalse
%
% Toggle whether \endnotepart shall add entries for parts in the toc's listing
% of endnotes as well - I suppose this is the most interesting switch for you:
\newif\ifendnotepartPartsInEndnotesToclisting
\endnotepartPartsInEndnotesToclistingtrue
%\endnotepartPartsInEndnotesToclistingfalse
%
%===============================================================================
\let\latexchapter\chapter
\makeatletter %changes the catcode of @ to 11
\newcommand\l@myhandmadepart{%
\@myundottedtocline {1}{1.5em}{2.3em}%
}
\newcommand\@myundottedtocline[5]{%
\ifnum #1>\c@tocdepth\else
\vskip\z@\@plus.2\p@
{%
\leftskip#2\relax
\rightskip\@tocrmarg
\parfillskip-\rightskip
\parindent#2\relax
\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\@tempdima#3\relax
\advance\leftskip\@tempdima
\null\nobreak\hskip-\leftskip
{#4}\nobreak\hfill\nobreak\null
\par
}%
\fi
}
\DeclareRobustCommand\sectiontomyhandmadepart{%
\let\l@section=\l@myhandmadepart
}%
\renewcommand\enoteheading{% changes being made here
\setcounter{secnumdepth}{-2}
\latexchapter*{\notesname\markboth{NOTES}{}}
\mbox{}\par\vskip-\baselineskip
\let\@afterindentfalse\@afterindenttrue
}
\makeatother %changes the catcode of @ back to 12
\usepackage{xparse}
\RenewDocumentCommand {\chapter}{som}{%
\IfBooleanTF{#1}%
{\latexchapter*{#3}%
\setcounter{endnote}{0}%
\addtoendnotes{%
\unexpanded{\enotedivision{\subsection}{#3}}%
}%
}%
{\IfNoValueTF{#2}%
{\latexchapter{#3}}%
{\latexchapter[#2]{#3}}%
\addtoendnotes{%
\unexpanded{\enotedivision{\subsection}}%
{\chaptername\ \thechapter. \unexpanded{#3}}}%
}%
}%
\NewDocumentCommand{\endnotepart}{som}{%
\IfBooleanTF{#1}%
{\ifendnotepartDoDocumentPartDivision\part*{#3}\addcontentsline{toc}{part}{#3}\fi
\setcounter{endnote}{0}%
\addtoendnotes{%
\ifendnotepartPartsInEndnotes
\unexpanded{%
\addtocontents{toc}{\begingroup\sectiontomyhandmadepart}%
\enotedivision{\section}{#3}}%
\relax
\noexpand\addtocontents{toc}{\endgroup}%
\else
\ifendnotepartPartsInEndnotesToclisting
\unexpanded{%
\addtocontents{toc}{\begingroup\sectiontomyhandmadepart}%
\addcontentsline{toc}{section}{#3}%
\addtocontents}{toc}{\endgroup}%
\fi
\fi
}%
}%
{\IfNoValueTF{#2}%
{\ifendnotepartDoDocumentPartDivision\part{#3}\fi}%
{\ifendnotepartDoDocumentPartDivision\part[#2]{#3}\fi}%
\addtoendnotes{%
\ifendnotepartPartsInEndnotes
\unexpanded{%
\addtocontents{toc}{\begingroup\sectiontomyhandmadepart}%
\enotedivision{\section}}%
{\partname\ \thepart. \unexpanded{#3}}%
\relax
\noexpand\addtocontents{toc}{\endgroup}%
\else
\ifendnotepartPartsInEndnotesToclisting
\unexpanded{%
\addtocontents{toc}{\begingroup\sectiontomyhandmadepart}%
\addcontentsline{toc}{section}}{\partname\ \thepart. \unexpanded{#3}}%
\noexpand\addtocontents{toc}{\endgroup}%
\fi
\fi
}%
}%
}%
\makeatletter
\def\enotedivision#1#2{\@ifnextchar\enotedivision{}{#1{#2}}}
\makeatletter
\usepackage{lettrine}
\setcounter{DefaultLines}{2}
\setlength{\DefaultFindent}{0em}
\setlength{\DefaultNindent}{.17em}
\renewcommand*{\DefaultLraise}{-0.05}
\renewcommand{\LettrineFontHook}{\usefont{U}{yinit}{m}{n}}
\renewcommand{\DefaultLoversize}{.1}
\definecolor{olivegreen}{cmyk}{0.64,0,0.95,0.40}
\begin{document}
\LARGE
%The Table of Contents
\renewcommand\contentsname{Table of Contents.}
\tableofcontents
\chapter*{INTRODUCTION}
\addcontentsline{toc}{chapter}{\textbf{INTRODUCTION.}}
\lettrine{\color{olivegreen}{T}}{\textbf{\color{olivegreen}his}} is the Introduction. Some words.\footnote{an endnote.} Some words.\footnote{an endnote.} Some words.
% PART I BEGINS HERE.
\endnotepart*{First part}
\chapter*{Chapter I}
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Chapter I.}}
\lettrine{\color{olivegreen}{T}}{\textbf{\color{olivegreen}his}} is Chapter I. of \textbf{PART I}. Some words.\footnote{an endnote.}Some words.\footnote{an endnote.}Some words.\footnote{an endnote.}
\chapter*{Chapter II}
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Chapter II.}}
\lettrine{\color{olivegreen}{T}}{\textbf{\color{olivegreen}his}} is Chapter II. Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}
% PART II BEGINS HERE.
\endnotepart*{Second part}
\chapter*{Chapter I}
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Chapter I.}}
\lettrine{\color{olivegreen}{T}}{\textbf{\color{olivegreen}his}} is Chapter I. of \textbf{PART II}.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}Some words.\footnote{An endnote.}
\chapter*{}
\addtocontents{toc}{\vskip 4pt}
\addcontentsline{toc}{chapter}{\textbf{Endnotes.}}
\renewcommand{\notesname}{Endnotes} % Renames `Notes' to `Endnotes'
\addtoendnotes{\unexpanded{\enotedivision{}{}}}
\theendnotes
\end{document}