設定本地目錄深度

設定本地目錄深度

我正在嘗試在一個大文件中設定主要內容\tableofcontents和幾個內容。\localtableofcontents該文件由引言、幾個部分、結論和參考書目組成。

至於目錄:

  • 引言、結論和參考書目應設定為主要章節\tableofcontents。後兩者應該是無編號的。
  • 每個部分的首頁將顯示\localtableofcontents相關部分的一個

我嘗試利用該{etoc}包來實現這一目標。以下 MWE 根據需要產生主目錄:

\documentclass{report}
\usepackage{titlesec}
\usepackage{etoc}

% to be able to show localtoc on part-page
\titleclass{\part}{top}
\titleformat{\part}[display]{\normalfont\huge\filcenter\bfseries}{\partname\ \thepart}{0pt}{}

\begin{document}

\tableofcontents

\chapter{Introduction}

\part{A Part}
\etocsettocstyle{}{}
\etocsetnexttocdepth{section}
\localtableofcontents
\chapter{A Chapter}
\section{A section}

\part{Another Part}
\etocsetnexttocdepth{section}
\localtableofcontents
\chapter{Another Chapter}
\section{Another Section}

% (1) change local toc's depth
%\etocsettocdepth{part}
%\etocignoretoctocdepth

% (2) limit scope of last local toc
%\etocsetnexttocdepth{part}
%\invisiblelocaltableofcontents

\chapter*{Conclusion}
% to add unnumbered conclusion to toc:
\addcontentsline{toc}{chapter}{Conclusion}

\bibliographystyle{plainnat}
% to add unnumbered bibliography to toc:
\addcontentsline{toc}{chapter}{\bibname}
\bibliography{\jobname}
\end{document}

然而,它未能排除最後的結論和參考書目\localtableofcontents

在此輸入影像描述

我的想法是:

  1. \etocsettocdepth最後\localtableofcontents在結論之前不再包含章節
  2. 限制最後的範圍\localtableofcontents,不再得出結論

我的嘗試在上面的 MWE 中被註解掉了。但他們也可以被處決,因為他們似乎無論如何都沒有效果...

如何從最後一個排除結論和參考書目\localtableofcontents

答案1

對於這樣的情況,etoc有命令\etocsetlocaltop.它的語法有點奇怪,要在文件part中插入分隔符toc,您可以編寫

\etocsetlocaltop.toc{part}

這會添加一個標記,toc其行為就像新的part開始一樣。更詳細的內容請參考第 48 章埃托克文檔

所以完整的文檔變成

\documentclass{report}
\usepackage{titlesec}
\usepackage{etoc}

% to be able to show localtoc on part-page
\titleclass{\part}{top}
\titleformat{\part}[display]{\normalfont\huge\filcenter\bfseries}{\partname\ \thepart}{0pt}{}

\begin{document}

\tableofcontents

\chapter{Introduction}

\part{A Part}
\etocsettocstyle{}{}
\etocsetnexttocdepth{section}
\localtableofcontents
\chapter{A Chapter}
\section{A section}

\part{Another Part}
\etocsetnexttocdepth{section}
\localtableofcontents
\chapter{Another Chapter}
\section{Another Section}

% limit scope of last local toc
\etocsetlocaltop.toc{part}

\chapter*{Conclusion}
% to add unnumbered conclusion to toc:
\addcontentsline{toc}{chapter}{Conclusion}

\bibliographystyle{plainnat}
% to add unnumbered bibliography to toc:
\addcontentsline{toc}{chapter}{\bibname}
\bibliography{\jobname}
\end{document}

在此輸入影像描述

相關內容