我喜欢在某些章节的开头添加一个目录,比如在 beamer 中我可以使用\tableofcontents[currentsection]
scrartcl 吗?
像这样:
\documentclass[10pt,a4paper]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
\tableofcontents %complete
\section{First}
\section{Second}
\tableofcontents %just subsection and subsubsection
\subsection{SecondSub}
\subsubsection{please}
\subsection{this}
\subsection{SecondSub2}
\subsection{parts}
\section{Third}
\subsection{another}
\end{document}
好像:
Inhaltsverzeichnis %complete
1 First
2 Second
2.1 SecondSub.......................2
2.1.1 please........................2
2.1.2 this..........................2
2.2. SecondSub2.....................3
2.2.1 parts.........................4
3 Third
3.1 another ........................5
1 First
2 Second
Inhaltsverzeichnis %just subsection and subsubsection
2.1 SecondSub.......................2
2.1.1 please........................2
2.1.2 this..........................2
2.2. SecondSub2.....................3
2.2.1 parts.........................4
2.1 SecondSub
2.1.1 please
2.1.2 this
2.2. SecondSub2
2.2.1 parts
3 Third
3.1 another
答案1
这是一个使用的示例etoc
。这只是一个起点。
\documentclass[10pt,a4paper]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{etoc}
\etocsettocstyle{\subsection*{\contentsname}}{}
\begin{document}
\tableofcontents
\section{First}
\section{Second}
\localtableofcontents
\subsection{SecondSub}
\subsubsection{please}
\subsection{this}
\subsection{SecondSub2}
\subsection{parts}
\section{Third}
\subsection{another}
\end{document}
答案2
您可以使用 KOMA-Script 的 alpha 包scrwfile
和一些命令的本地重新定义\l@…
以及本地更改tocdepth
:
\documentclass[10pt,a4paper]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{scrwfile}
\makeatletter
\newcounter{sectiontocdepth}
\setcounter{sectiontocdepth}{\subsubsectiontocdepth}
\newcommand*{\sectiontoc}{%
\edef\reserved@a{\noexpand\setcounter{tocdepth}{\the\value{tocdepth}}}%
\begingroup
\setcounter{tocdepth}{\sectiontocdepth}%
\let\l@part\@gobbletwo
\def\l@section##1##2{%
\begingroup
\def\numberline####1{%
\ifstr{####1}{\thesection}{%
\setcounter{tocdepth}{\value{sectiontocdepth}}%
}{%
\setcounter{tocdepth}{\sectiontocdepth}%
}%
}%
\sbox\@tempboxa{##1}%
\endgroup
}%
\listoftoc*{toc}%
\endgroup
\reserved@a
}
\makeatother
\setcounter{sectiontocdepth}{\subsubsectiontocdepth}
\begin{document}
\tableofcontents %complete
\section{First}
\section{Second}
\sectiontoc
\subsection{SecondSub}
\subsubsection{please}
\subsection{this}
\subsection{SecondSub2}
\subsection{parts}
\section{Third}
\subsection{another}
\end{document}
请注意,它只适用于编号部分。
如果您想要在目录部分上方添加标题,请替换
\listoftoc*{toc}
经过
\setuptoc{toc}{leveldown}%
\listoftoc{toc}%
你会得到:
scrwfile
使用Alpha 包来避免\tableofcontents
(和\listoftoc*
或listoftoc
)删除文件内容toc
。请参阅手册以了解可能出现的问题。
答案3
问题当前章节的目录以突出显示(Beamer 中没有)被标记为完全重复,但我不这么认为。(或者也许问题是,但现有的答案似乎略有不同;这里的部分本身是印刷目录的一部分)
因此我在这里提供该问题的答案。
\documentclass[a4paper]{article}
\usepackage{xcolor}
\usepackage{etoc}
\usepackage{hyperref}
\makeatletter
\DeclareRobustCommand{\SectionFromToc}[1]{\ifnum#1=\value{section}%
\color{black}%
\expandafter\@SectionFromToc\else\color{gray}\fi}
% without hyperref, do not use #4 here.
\def\@SectionFromToc \contentsline#1#2#3#4{%
\section*{{\def\mysecnumber{\makebox[1.5em][l]}#2}}
}
\DeclareRobustCommand\mysecnumber[1]{}
\makeatother
\newcommand\mysection[1]{%
\clearpage
\refstepcounter{section}%
\addtocontents{toc}{\SectionFromToc{\the\value{section}}}%
\addcontentsline{toc}{section}{\mysecnumber{\the\value{section}}#1}%
\tableofcontents
}
\etocsettocstyle{}{\clearpage}
\begin{document}
\mysection{Section 1}
Content of Section 1
\mysection{Section 2}
Content of Section 2
\mysection{Section 3}
Content of Section 3
\mysection{Section 4}
Content of Section 4
\end{document}
为了更好地说明结果,下面是
\etocsettocstyle{}{\vspace{2\baselineskip}}
以下是一些添加的小节: