在我的文档中,我有两个“部分”,我希望它们在目录中有不同的显示效果。第一个“部分”的条目之间应该有跳跃section
,但第二个“部分”的section
条目不应该有垂直空间(例如tocbeforeskip=0ex
)、bfseries 和 normalsize。
但应用例如
\RedeclareSectionCommands[
tocbeforeskip=0ex,
]{section}
在 -entry之前chapter
对 -entries 没有影响section
:
这是我的 MWE:
\documentclass[
headings=optiontotoc,% switch on extended optional argument parsing
]{scrbook}
% ==== TOC style
\newcommand\tocgobble[1]{}% <- added
\newcommand\tocpageseparator{\normalsize\bfseries\,\mbox{---}\,}
\newcommand\tocpagenumberbox[1]{\mbox{#1}}% <- added
\KOMAoptions{toc=indentunnumbered}
\RedeclareSectionCommands[
tocraggedpagenumber,
toclinefill=\tocpageseparator,
tocindent=0em,
tocnumwidth=4em,
tocpagenumberbox=\tocpagenumberbox,% <- added
% tocpagenumberformat=\textsf,
beforeskip= 0ex,
afterskip= 0.01ex
]{section,subsection,subsubsection}
\RedeclareSectionCommands[
tocbeforeskip=2ex,
tocentryformat=\bfseries\large,
]{section}
% no page number for chapters in TOC
\RedeclareSectionCommands[
tocraggedpagenumber,
toclinefill=\tocgobble,
tocindent=0em,
tocnumwidth=4em,
tocpagenumberbox=\tocgobble,% <- added
% tocpagenumberformat=\textsf,
beforeskip= 0ex,
afterskip=0.1ex,
tocentryformat=\bfseries\Large\sffamily,
]{chapter}
\begin{document}
\tableofcontents
\chapter{Foo}
\section{Bar}
\subsection{FooBar}
\subsection{FooBar}
\subsection{FooBar}
\section{Bar}
\subsection{FooBar}
\subsection{FooBar}
\section{Bar}
\subsection{FooBar}
\subsection{FooBar}
\subsection{FooBar}
% ===============================
% Change style of TOC from here on.
\RedeclareSectionCommands[
tocbeforeskip=0ex,
]{section}
%===============================
\chapter{Projects}
\section{Bar}
\section{Bar}
\section{Bar}
\section{Bar}
\section{Bar}
\section{Bar}
\end{document}
答案1
免责声明:我不建议对目录中的章节级别使用不同的格式设置。
但有可能:
\addtocontents{toc}{%
\RedeclareSectionCommands[
tocbeforeskip=0ex,
tocentryformat=\bfseries\normalsize
]{section}%
}
例子:
\documentclass[
headings=optiontotoc,% switch on extended optional argument parsing
]{scrbook}
% ==== TOC style
\newcommand\tocgobble[1]{}% <- added
\newcommand\tocpageseparator{\normalsize\bfseries\,\mbox{---}\,}
\newcommand\tocpagenumberbox[1]{\mbox{#1}}% <- added
\KOMAoptions{toc=indentunnumbered}
\RedeclareSectionCommands[
tocraggedpagenumber,
toclinefill=\tocpageseparator,
tocindent=0em,
tocnumwidth=4em,
tocpagenumberbox=\tocpagenumberbox,% <- added
% tocpagenumberformat=\textsf,
beforeskip= 0ex,
afterskip= 0.01ex
]{section,subsection,subsubsection}
\RedeclareSectionCommands[
tocbeforeskip=2ex,
tocentryformat=\bfseries\large,
]{section}
% no page number for chapters in TOC
\RedeclareSectionCommands[
tocraggedpagenumber,
toclinefill=\tocgobble,
tocindent=0em,
tocnumwidth=4em,
tocpagenumberbox=\tocgobble,% <- added
% tocpagenumberformat=\textsf,
beforeskip= 0ex,
afterskip=0.1ex,
tocentryformat=\bfseries\Large\sffamily,
]{chapter}
\begin{document}
\tableofcontents
\chapter{Foo}
\section{Bar}
\subsection{FooBar}
\subsection{FooBar}
\subsection{FooBar}
\section{Bar}
\subsection{FooBar}
\subsection{FooBar}
\section{Bar}
\subsection{FooBar}
\subsection{FooBar}
\subsection{FooBar}
% ===============================
% Change style of TOC from here on. (not recommended)
\addtocontents{toc}{%
\RedeclareSectionCommands[
tocbeforeskip=0ex,
tocentryformat=\bfseries\normalsize
]{section}%
}
%===============================
\chapter{Projects}
\section{Bar}
\section{Bar}
\section{Bar}
\section{Bar}
\section{Bar}
\section{Bar}
\end{document}