我需要在书籍类 Latex 文档的末尾逐章列出尾注。我从以下代码中借用了
\documentclass[12pt]{book}
\usepackage{endnotes,chngcntr}
\counterwithin*{endnote}{chapter} % Reset endnote numbering every new chapter
\makeatletter
\renewcommand\enoteheading{%
\setcounter{secnumdepth}{-2}
\chapter*{\notesname}
\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{\unexpanded{\enotedivision{\subsection}{#3}}}
}
}
\makeatletter
\def\enotedivision#1#2{\@ifnextchar\enotedivision{}{#1{#2}}}
\makeatletter
\begin{document}
\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 will appear at the end, under the heading "Yet Another Amazing
Story", with the counter reset to 1, since this is the first endnote of this chapter.}
\addtoendnotes{\unexpanded{\enotedivision{}{}}}
\theendnotes
\end{document}
对我来说效果很好,除了在尾注中我只得到章节标题,但没有章节编号。如何编辑它以包含章节编号?
例如:现在我得到这个:
笔记
“奇妙的故事”
(该章注释列表)
我要这个:
笔记
“第 1 章 奇妙的故事”
(该章注释列表)
答案1
只需更改重新定义\chapter
如下
\RenewDocumentCommand{\chapter}{som}{%
\IfBooleanTF{#1}
{\latexchapter*{#3}}
{\IfNoValueTF{#2}
{\latexchapter{#3}}
{\latexchapter[#2]{#3}}%
\addtoendnotes{%
\noexpand\enotedivision{\noexpand\subsection}
{\chaptername\ \thechapter. \unexpanded{#3}}}%
}%
}
无论如何,这是完整的例子
\documentclass[12pt]{book}
\usepackage{endnotes,chngcntr}
\counterwithin*{endnote}{chapter} % Reset endnote numbering every new chapter
\makeatletter
\renewcommand\enoteheading{%
\setcounter{secnumdepth}{-2}
\chapter*{\notesname}
\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}
\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 will appear at the end, under the heading "Yet Another Amazing
Story", with the counter reset to 1, since this is the first endnote of this chapter.}
\addtoendnotes{\unexpanded{\enotedivision{}{}}}
\theendnotes
\end{document}