对于研究论文,我需要添加附录,该附录需要有自己的目录。
为了符合指导方针,我还需要将参考书目和声明放在附录之后。两者都只能出现在主目录中。
另外,在另一个网站上,我找到了以下方法,这种方法看起来很有希望,但由于对 LaTeX 还很陌生,我找不到解决我的问题的方法。
是否有可能将参考书目和声明添加到 maintoc 中?
\documentclass{scrreprt}
\usepackage{blindtext}
\makeatletter
\newcommand*{\maintoc}{
\begingroup
\@fileswfalse
\renewcommand*{\appendixattoc}{
\value{tocdepth}=-10000
}
\tableofcontents
\endgroup
}
\newcommand*{\appendixtoc}{
\begingroup
\edef\@alltocdepth{\the\value{tocdepth}}
\setcounter{tocdepth}{-10000}
\renewcommand*{\appendixattoc}{
\setcounter{tocdepth}{\@alltocdepth}
}
\tableofcontents
\setcounter{tocdepth}{\@alltocdepth}
\endgroup
}
\newcommand*{\appendixattoc}{
}
\g@addto@macro\appendix{
\if@openright\cleardoublepage\else\clearpage\fi
\phantomsection
\addcontentsline{toc}{chapter}{\appendixname}
\addtocontents{toc}{\protect\appendixattoc}
}
\makeatother
\begin{document}
\maintoc
\chapter{Chapter I}
\section{Section I}
\chapter{Chapter II}
\appendix
\appendixtoc
\chapter{Annex I}
\section{Section of Annex I}
\chapter{Annex II}
\printbibliography
\addchap{Declaration of academic honesty}
\end{document}
答案1
更新(基于https://komascript.de/node/2115)
以下是不带任何附加包的建议:
\documentclass[bibliography=totoc]{scrreprt}
%%%
\DeclareNewTOC[
owner=\jobname,
listname={\contentsname~(\appendixname)}
]{atoc}
\makeatletter
\newenvironment{appendixwithtoc}{%
\cleardoublepage
\appendix
\addchaptertocentry{}{\appendixname}
\listofatocs
\renewcommand*{\ext@toc}{atoc}%
\scr@ifundefinedorrelax{hypersetup}{}{\hypersetup{bookmarkstype=atoc}}%
}{%
\renewcommand*{\ext@toc}{toc}%
\scr@ifundefinedorrelax{hypersetup}{}{\hypersetup{bookmarkstype=toc}}%
}
\makeatother
%%%
\usepackage[backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\chapter{Chapter I}
\section{Section I}
\chapter{Chapter II}
\cite{baez/article}
\begin{appendixwithtoc}
\chapter{Annex I}
\section{Section of Annex I}
\chapter{Annex II}
\end{appendixwithtoc}
\printbibliography
\addchap{Declaration of academic honesty}
\end{document}
结果和原答案相同。
注意:如果您收到有关未定义命令的错误消息\ext@toc
,请更新您的 KOMA-Script 版本或将以下代码添加到您的序言中:
\ifundefinedorrelax{ext@toc}{%
\newcommand*{\ext@toc}{toc}
\renewcommand{\addtocentrydefault}[3]{%
\expandafter\tocbasic@addxcontentsline\expandafter{\ext@toc}{#1}{#2}{#3}%
}
}{}
原始答案
以下是使用的建议scrwfile
仅适用于 KOMA-Script 类:
\documentclass[bibliography=totoc]{scrreprt}
\usepackage[utf8]{inputenc}
%%%
\usepackage{scrwfile}
\TOCclone[\contentsname~(\appendixname)]{toc}{atoc}
\newcommand\StartAppendixEntries{}
\AfterTOCHead[toc]{%
\renewcommand\StartAppendixEntries{\value{tocdepth}=-10000\relax}%
}
\AfterTOCHead[atoc]{%
\edef\maintocdepth{\the\value{tocdepth}}%
\value{tocdepth}=-10000\relax%
\renewcommand\StartAppendixEntries{\value{tocdepth}=\maintocdepth\relax}%
}
\newenvironment{appendixwithtoc}{%
\cleardoublepage
\appendix
\addchaptertocentry{}{\appendixname}
\addtocontents{toc}{\protect\begingroup}
\addtocontents{toc}{\protect\StartAppendixEntries}
\listofatoc
}{%
\addtocontents{toc}{\protect\endgroup}
}
%%%
\usepackage[backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\chapter{Chapter I}
\section{Section I}
\chapter{Chapter II}
\cite{baez/article}
\begin{appendixwithtoc}
\chapter{Annex I}
\section{Section of Annex I}
\chapter{Annex II}
\end{appendixwithtoc}
\printbibliography
\addchap{Declaration of academic honesty}
\end{document}
请注意,这scrwfile
仍然是一个 alpha 版本,但它是 KOMA-Script 包的一部分。