我所拥有的是目录中的分组前置条目(类似章节),其余章节具有更大的垂直空间。
我想要将分组部分的字体样式更改为普通字体或斜体,同时保持其余条目不变。我该怎么做?
(将来我可能会将第 1 至 3 章的条目更改为小写字母或其他格式......)
\documentclass{memoir}
\usepackage{etoolbox}
\setlength{\cftbeforesectionskip}{4pt}
\begin{document}
\tableofcontents
\chapter*{Foreword}
\addcontentsline{toc}{chapter}{Foreword}
\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
\pretocmd{\chapter}{\addtocontents{toc}{\addvspace{16pt}}}{}{}
\chapter{Chapter One}
\section{Section One One}
\section{Section One Two}
\section{Section One Three}
\section{Section One Four}
\chapter{Chapter Two}
\section{Section Two One}
\section{Section Two Two}
\section{Section Two Three}
\chapter{Chapter Three}
\section{Section Three One}
\section{Section Three Two}
\section{Section Three Three}
\section{Section Three Four}
\section{Section Three Five}
\end{document}
这是问题的延续暂时更改目录中章节的垂直间距. 包etoolbox
用于对前言条目进行分组。
答案1
声明一个新的布尔开关(例如specialtoc
)。.toc
在文档主体开始时将其(在文件内部)设置为 true,在主要章节开始时将其设置为 false。重新定义\cftchapterfont
和\cftchapterpagefont
(负责格式化 ToC 章节条目),使其含义取决于的状态specialtoc
。
\documentclass{memoir}
\setlength{\cftbeforesectionskip}{4pt}
\usepackage{etoolbox}
\newbool{specialtoc}
\renewcommand{\cftchapterfont}{%
\ifbool{specialtoc}{%
\itshape
}{%
\bfseries
}%
}
\renewcommand{\cftchapterpagefont}{%
\ifbool{specialtoc}{%
\itshape
}{%
\bfseries
}%
}
\begin{document}
\addtocontents{toc}{\protect\booltrue{specialtoc}}
\tableofcontents
\chapter*{Foreword}
\addcontentsline{toc}{chapter}{Foreword}
\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
\addtocontents{toc}{\protect\boolfalse{specialtoc}}
\pretocmd{\chapter}{\addtocontents{toc}{\addvspace{16pt}}}{}{}
\chapter{Chapter One}
\section{Section One One}
\section{Section One Two}
\section{Section One Three}
\section{Section One Four}
\chapter{Chapter Two}
\section{Section Two One}
\section{Section Two Two}
\section{Section Two Three}
\chapter{Chapter Three}
\section{Section Three One}
\section{Section Three Two}
\section{Section Three Three}
\section{Section Three Four}
\section{Section Three Five}
\end{document}
答案2
尽管 lockstep 已经给出了很好的解决方案,但我将根据 daleif 对\cftinserthook
和的评论添加最小解决方案\cftinsertcode
。这样就etoolbox
根本不需要 -package 了。
\documentclass{memoir}
\setlength{\cftbeforechapterskip}{4pt}
\renewcommand*{\cftchapterfont}{\itshape}
\cftinsertcode{SPECIALTOC}{%
\renewcommand*{\cftchapterfont}{\bfseries}%
\setlength{\cftbeforechapterskip}{16pt}%
}
\begin{document}
\tableofcontents
\chapter*{Foreword}
\addcontentsline{toc}{chapter}{Foreword}
\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
\cftinserthook{toc}{SPECIALTOC}
\chapter{Chapter One}
\section{Section One One}
\section{Section One Two}
\chapter{Chapter Two}
\section{Section Two One}
\chapter{Chapter Three}
\section{Section Three One}
\section{Section Three Two}
\section{Section Three Three}
\end{document}
输出与lokcstep的解决方案类似。