我的文档分为序言部分和编号部分(标记为“# [章节名称]”等)。所有这些部分都有注释,这些注释位于文档末尾(“注释”部分)。我需要将“注释”部分划分为子部分,每个子部分都有来自相应部分的注释列表。我在这个网站上搜索提示,找到了一个解决方案,我将其放入了我的 latex 文件的序言中:
\documentclass{article}
\usepackage{graphicx}
\usepackage{setspace}\doublespacing
\usepackage{endnotes}
\usepackage{natbib}
\bibliographystyle{apalike}
\usepackage{lipsum}
%--- Endnotes rules
\counterwithin*{endnote}{section} % Reset endnote numbering every new part
\makeatletter
\renewcommand\enoteheading{%
\setcounter{secnumdepth}{-2}
\section*{\notesname}
\addtocontents{toc}{\protect\addvspace{10pt}} % adjust to suit
\addcontentsline{toc}{section}{\notesname}
\mbox{}\par\vskip-\baselineskip
\let\@afterindentfalse\@afterindenttrue
}
\makeatother
\usepackage{xparse}
\let\latexsection\section
\RenewDocumentCommand{\section}{som}{%
\IfBooleanTF{#1}
{\latexsection*{#3}}
{\IfNoValueTF{#2}
{\latexsection{#3}}
{\latexsection[#2]{#3}}%
\addtoendnotes{\unexpanded{\subsection{#3}}}
}
}
%--- ...end of the Endnotes rules
\begin{document}
\let\footnote=\endnote
\pagenumbering{roman}
{\let\bfseries\mdseries \tableofcontents} \newpage
\section*{Preface}
\addcontentsline{toc}{section}{\uppercase{Preface}}
\lipsum[1-3]\footnote{foo bar baz in Preface}
\newpage
\pagenumbering{arabic}
\section{Intro \& Plan}
\lipsum[1-2]\footnote{foo bar baz in Ch1}
\newpage
\section{Literature Review}
\lipsum[1-2]\footnote{foo bar baz in Ch2}
\newpage
\theendnotes
\addcontentsline{toc}{section}{\uppercase{Notes}}
\end{document}
输出的 pdf 文件产生了“注释”部分的外观(见下图),其中缺少“前言”部分的标题。除此之外,我需要编号部分的标题包含“章节 # [章节名称]”。最后,文档的目录必须隐藏“注释”目录行之后的子部分目录行。
答案1
似乎你正在尝试改编@egreg关于这个问题的答案article
(https://tex.stackexchange.com/a/109566/105447看起来最接近您的用例)。以后,请报告您使用的代码的来源,这不仅是因为值得赞扬,而且因为如果任何试图帮助您的人知道工作版本应该是什么,他们就会更容易。
无论如何,这里有一个版本article
:
\documentclass{article}
\usepackage{setspace}
\doublespacing
\usepackage{endnotes}
\usepackage{lipsum}
%--- Endnotes
% Adapted from https://tex.stackexchange.com/a/109566/105447
% Reset endnote numbering every section
\counterwithin*{endnote}{section}
\makeatletter
\NewCommandCopy\latexsection\section
\renewcommand\enoteheading{%
\setcounter{secnumdepth}{-2}
\latexsection*{\notesname}
\addtocontents{toc}{\protect\addvspace{10pt}} % adjust to suit
\addcontentsline{toc}{section}{\MakeUppercase{\notesname}}
% I don't think this is needed in this case, and you get excessive space
% with it imho.
% \mbox{}\par\vskip-\baselineskip
\let\@afterindentfalse\@afterindenttrue
}
\makeatother
% It's no longer need to load xparse for \RenewDocumentCommand
% \usepackage{xparse}
\RenewDocumentCommand{\section}{som}{%
\IfBooleanTF{#1}
{\latexsection*{#3}%
\setcounter{endnote}{0}%
\addtoendnotes{%
\noexpand\enotedivision{\noexpand\subsubsection*}
{\unexpanded{#3}}}%
}
{\IfNoValueTF{#2}
{\latexsection{#3}}
{\latexsection[#2]{#3}}%
\addtoendnotes{%
\noexpand\enotedivision{\noexpand\subsubsection*}
{\thesection. \unexpanded{#3}}}%
}%
}
\makeatletter
\def\enotedivision#1#2{\@ifnextchar\enotedivision{}{#1{#2}}}
\makeatletter
%--- ...end of Endnotes
\let\footnote=\endnote
\begin{document}
\pagenumbering{roman}
% That's not a very LaTeX-y way to format your ToC, but you can have it your
% way...
{\let\bfseries\mdseries \tableofcontents}
\newpage
\section*{Preface}
\addcontentsline{toc}{section}{\MakeUppercase{Preface}}
\lipsum[1-3]\footnote{foo bar baz in Preface}
\newpage
\pagenumbering{arabic}
\section{Intro \& Plan}
\lipsum[1-2]\footnote{foo bar baz in Ch1}
\newpage
\section{Literature Review}
\lipsum[1-2]\footnote{foo bar baz in Ch2}
\addtoendnotes{\unexpanded{\enotedivision{}{}}}
\newpage
\theendnotes
\end{document}