我正在寻找一种方法,使目录中的前言和后言章节都变为非粗体斜体。
对于前言章节,我找到了 Christian Hupfer 提出的一个简短且有效的解决方案:目录中前言章节的不同样式
它使用该tocloft
包及其命令\cftchapterfont
和\cftchapterpagefont
。
我的问题是如何扩展它以使其也适用于后述章节?
答案1
\appendix
如果您使用 KOMA,只需以相同的方式重新定义宏,就像链接问题的 OP 一样:
\documentclass{scrbook}
\makeatletter
\newcommand\matter@switch{}
\addtokomafont{chapterentry}{\matter@switch}
\g@addto@macro\frontmatter{%
\addtocontents{toc}{%
\protect\renewcommand\protect\matter@switch{\normalfont\itshape}%
}%
}
\g@addto@macro\mainmatter{%
\addtocontents{toc}{%
\protect\renewcommand\protect\matter@switch{}%
}%
}
\g@addto@macro\appendix{%
\addtocontents{toc}{%
\protect\renewcommand\protect\matter@switch{\normalfont\itshape}%
}%
}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\chapter{Preface}
\chapter{Acknowledgements}
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\appendix
\chapter{Appendix}
\end{document}
或者如果您不使用 KOMA,请引入类似的代码,但是tocloft
:
\documentclass{book}
\usepackage{tocloft}%
\begin{document}
\let\cftchapfontorig\cftchapfont
\let\cftchappagefontorig\cftchappagefont
\renewcommand{\cftchapfont}{\itshape}
\renewcommand{\cftchappagefont}{\itshape}%
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\addtocontents{toc}{\protect\renewcommand{\protect\cftchapfont}{\cftchapfontorig}}
\addtocontents{toc}{\protect\renewcommand{\protect\cftchappagefont}{\cftchappagefontorig}}
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\addtocontents{toc}{\protect\renewcommand{\protect\cftchapfont}{\itshape}}
\addtocontents{toc}{\protect\renewcommand{\protect\cftchappagefont}{\itshape}}
\appendix
\chapter{Appendix}
\end{document}
答案2
这是使用包的另一个建议tocbasic
。
有KOMA-Script 类:
\documentclass{scrbook}% loads tocbasic automatically
\DeclareTOCStyleEntry[
entryformat=\chapterentryformat,
pagenumberformat=\chapterentryformat
]{tocline}{chapter}
\newif\ifmainmatterintoc
\newcommand*\chapterentryformat[1]
{{\ifmainmatterintoc\usekomafont{chapterentry}\else\normalfont\slshape\fi#1}}
\begin{document}
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\mainmatter
\addtocontents{toc}{\protect\mainmatterintoctrue}
\chapter{First Chapter}
\chapter{Second Chapter}
\backmatter
\addtocontents{toc}{\protect\mainmatterintocfalse}
\chapter{First Backmatter Chapter}
\chapter{Second Backmatter Chapter}
\end{document}
有标准班:
\documentclass{book}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[
entryformat=\chapterentryformat,
pagenumberformat=\chapterentryformat
]{tocline}{chapter}
\newif\ifmainmatterintoc
\newcommand*\chapterentryformat[1]
{{\ifmainmatterintoc\bfseries\sffamily\else\normalfont\slshape\fi#1}}
\begin{document}
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\mainmatter
\addtocontents{toc}{\protect\mainmatterintoctrue}
\chapter{First Chapter}
\chapter{Second Chapter}
\backmatter
\addtocontents{toc}{\protect\mainmatterintocfalse}
\chapter{First Backmatter Chapter}
\chapter{Second Backmatter Chapter}
\end{document}
也可以在序言中\mainmatter
修补:\appendix
\documentclass{book}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[
entryformat=\chapterentryformat,
pagenumberformat=\chapterentryformat
]{tocline}{chapter}
\newif\ifmainmatterintoc
\newcommand*\chapterentryformat[1]
{{\ifmainmatterintoc\bfseries\sffamily\else\normalfont\slshape\fi#1}}
\usepackage{xpatch}
\xapptocmd\mainmatter{\addtocontents{toc}{\protect\mainmatterintoctrue}}
{}{\mmPatchFailed}
\xapptocmd\backmatter{\addtocontents{toc}{\protect\mainmatterintocfalse}}
{}{\appPatchFailed}
\begin{document}
\frontmatter
\chapter{Preface}
\chapter{Acknowledgements}
\tableofcontents
\mainmatter
\chapter{First Chapter}
\chapter{Second Chapter}
\backmatter
\chapter{First Backmatter Chapter}
\chapter{Second Backmatter Chapter}
\end{document}