我必须编写一个 Exposé,它需要在文档的某个部分内包含第二个目录。要求与之前讨论的基本上相同这个问题,不同之处在于,我不仅需要\section
和\subsection
,还需要\subsubsection
。
编辑:似乎我的问题不够详细,因为它已被关闭,因为它已经在其他地方得到回答了。链接的问题多次涉及同一个目录。我确实需要一个单独的目录,其中包含与当前文档无关的单个标题。目录需要是未来文档的目录,因此它不能引用当前文档的任何常规标题。
\documentclass[]{scrartcl}
\begin{document}
\tableofcontents
\section{Introduction}
Lorem ipsum...
\section{Some text}
blah blah
\section{Structure}
%TOC of future document without page numbers, not referring to other current headings.
\section{Discussion}
Some Text
\end{document}
看起来应该是这样的:
Table of Contents
1 Introduction..................................1
2 Some text.....................................2
3 Structure.....................................4
4 Discussion....................................6
1 Introduction
Lorem ipsum...
2 Some text
blah blah
3 Structure
%TOC of future document without page numbers
1 First Chapter
2 Second Chapter
2.1 A Subsection
2.2 Another Subsection
2.2.1 A Subsubsection
2.2.1 Another Subsubsection
3 Last Chapter
4 Discussion
Some Text
我基本上能够实施提议的解决方案并且还尝试过自己添加\subsubsection
但是没有成功。
建议使用的其他解决方案enumitem
与我的常规目录的样式不同。希望附加目录与文档的主目录具有相同的样式。
您对如何在 KOMA-Script 解决方案中添加第三层有什么建议吗?非常感谢您的支持!
答案1
如果你想subsubsection
在结构部分中包含此解决方案,添加subsubsection
到最后一个参数\DeclareTOCStyleEntries
latex
\BeforeStartingTOC[str]{%
\DeclareTOCStyleEntries[
linefill=\hfill,%
pagenumberformat=\gobble%
]{tocline}{section,subsection,subsubsection}% <=== subsubsection added
}
并定义新的计数器strsubsubsection
\newcounter{strsubsubsection}
\counterwithin{strsubsubsection}{strsubsection}
例子:
\documentclass{scrartcl}
\DeclareNewTOC{str}
\BeforeStartingTOC[str]{%
\DeclareTOCStyleEntries[
linefill=\hfill,%
pagenumberformat=\gobble%
]{tocline}{section,subsection,subsubsection}% <=== subsubsection added
}
\newcommand\gobble[1]{}
\newcounter{strsection}
\newcounter{strsubsection}
\counterwithin{strsubsection}{strsection}
\newcounter{strsubsubsection}% <=== added
\counterwithin{strsubsubsection}{strsubsection}% <=== added
\newcommand\addstr[2]{%
\stepcounter{str#1}%
\addxcontentsline{str}{#1}[\csname thestr#1\endcsname]{#2}%
}
\begin{document}
\tableofcontents
\section{Introduction}
Lorem ipsum...
\section{Some text}
blah blah
\section{Structure}
\listoftoc*{str}
\addstr{section}{First Section}
\addstr{section}{Second Section}
\addstr{subsection}{A Subsection}
\addstr{subsection}{Another Subsection}
\addstr{subsubsection}{A Subsubsection}% <=== added
\addstr{subsubsection}{Another Subsubsection}% <=== added
\addstr{section}{Last Section}
\section{Discussion}
\end{document}
但是如果您想使用带有章节的类(即scrreprt
或scrbook
),那么您必须将章节级别添加到结构章节中:
\documentclass{scrreprt}
\DeclareNewTOC{str}
\BeforeStartingTOC[str]{%
\DeclareTOCStyleEntries[
linefill=\hfill,% no dots
pagenumberformat=\gobble% no page number
]{tocline}{chapter,section,subsection}% <=== chapter added
}
\newcommand\gobble[1]{}
\newcounter{strchapter}% <=== added
\newcounter{strsection}
\counterwithin{strsection}{strchapter}% <=== changed
\newcounter{strsubsection}
\counterwithin{strsubsection}{strsection}
\newcommand\addstr[2]{%
\stepcounter{str#1}%
\addxcontentsline{str}{#1}[\csname thestr#1\endcsname]{#2}%
}
\begin{document}
\tableofcontents
\chapter{Introduction}
Lorem ipsum...
\chapter{Some text}
blah blah
\chapter{Structure}
\listoftoc*{str}
\addstr{chapter}{First Chapter}
\addstr{chapter}{Second Chapter}
\addstr{section}{A Section}
\addstr{section}{Another Section}
\addstr{subsection}{A Subsection}% <=== added
\addstr{subsection}{Another Subsection}% <=== added
\addstr{section}{Last Chapter}
\chapter{Last Chapter}
\end{document}
答案2
这是针对多个 ToC、LoF 等的通用解决方案。它并不特定于类scrartcl
。请注意,它涉及重新定义内核宏。
% tocsprob.tex SE 581163
\documentclass[]{scrartcl}
% Modify a kernel macro so that ToC, etc files only closed at the document end
\makeatletter
\renewcommand{\@starttoc}[1]{%
\begingroup\makeatletter
\@input{\jobname.#1}%
\if@filesw
\AtEndDocument{%
\expandafter\newwrite\csname tf@#1\endcsname
\immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
}%
\fi
\@nobreakfalse
\endgroup}
\makeatother
\begin{document}
\tableofcontents
\section{Introduction}
Lorem ipsum...
\section{Some text}
blah blah
\subsection{A subsection}
\subsubsection{A subsubsection}
\paragraph{A paragraph} Text
\section{Structure}
Additional TOC defined here
% have ToC include \paragraph s
\addtocontents{toc}{\protect\setcounter{tocdepth}{4}}
\tableofcontents
\end{document}
默认情况下,\subsubsection
s 包含在 ToC 中。我已演示如何\paragraph
在第二个 ToC 中包含 s,以防您需要。
(该类memoir
默认允许多个 ToC 等。)