我想进一步自定义目录,但似乎无法包括\centering
或\par
- 例如,类似\@chapapp\ \HeadingNumber\par
。否则,颜色/大小/字体更改可以正常工作。
\documentclass{mwbk}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\usepackage{blindtext}
\makeatletter
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries \LARGE % added for large font for chapters
\advance\leftskip\@tempdima
\hskip -\leftskip %\@chapapp~ \par % added \@chapapp~ \par
#1\nobreak \raggedright % originally \hfil
%added for leaders (dots) in chapter in toc
%\xleaders\hbox{$\m@th
% \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
% mu$}\hfill%
%%%
\nobreak\hb@xt@\@pnumwidth{\hss \itshape \fbox{#2}}\par\vspace{12pt} % ADDED VSPACE
\penalty\@highpenalty
\endgroup
\fi}
%for mwbk
\def\mw@seccntformat#1{#1\enspace} % para tirar o ponto após número do capítulo
\renewcommand*\chapter@toc{%
\ifHeadingNumbered\typeout{\@chapapp\space\thechapter.}\fi
\addcontentsline{toc}{chapter}{%
\ifHeadingNumbered
\mw@seccntformat{\color{ForestGreen}\@chapapp\ \HeadingNumber}%
\fi
\color{yellow}\HeadingTOCText}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
}
\makeatother
\begin{document}
\tableofcontents
\chapter{Some chapter}
\blinddocument
\blinddocument
\end{document}
答案1
从问题来看,并不清楚具体想要什么,所以我假设 OP 想要的是黄色文本,位于目录的中心,而不是文档的中心。另外,如何以这种方式处理章节名称的多行条目?对于一般方法,我用\hfill
s 包围了标题目录文本,如下所示
\addcontentsline{toc}{chapter}{%
\ifHeadingNumbered
\mw@seccntformat{\color{ForestGreen}\@chapapp\ \HeadingNumber}%
\fi
\color{yellow}\hfill\HeadingTOCText\hfill}%
但是,这不能处理多行章节名称。对于这些,我需要使用 手动中断\manbreak
,如\chapter{This is a really extra long \manbreak chapter name}
。此宏以一种方式定义用于目录构造,并\relax
通过以下方式定义用于文档的其余部分
\def\manbreak{\hfill\hfill\\\mbox{}\hfill\hfill}
\tableofcontents
\let\manbreak\relax
这是 MWE。
\documentclass{mwbk}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\usepackage{blindtext}
\makeatletter
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries \LARGE % added for large font for chapters
\advance\leftskip\@tempdima
\hskip -\leftskip %\@chapapp~ \par % added \@chapapp~ \par
#1\nobreak \raggedright % originally \hfil
%added for leaders (dots) in chapter in toc
%\xleaders\hbox{$\m@th
% \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
% mu$}\hfill%
%%%
\nobreak\hb@xt@\@pnumwidth{\hss \itshape \fbox{#2}}\par\vspace{12pt} % ADDED VSPACE
\penalty\@highpenalty
\endgroup
\fi}
%for mwbk
\def\mw@seccntformat#1{#1\enspace} % para tirar o ponto após número do capítulo
\renewcommand*\chapter@toc{%
\ifHeadingNumbered\typeout{\@chapapp\space\thechapter.}\fi
\addcontentsline{toc}{chapter}{%
\ifHeadingNumbered
\mw@seccntformat{\color{ForestGreen}\@chapapp\ \HeadingNumber}%
\fi
\color{yellow}\hfill\HeadingTOCText\hfill}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
}
\makeatother
\begin{document}
\def\manbreak{\hfill\hfill\\\mbox{}\hfill\hfill}
\tableofcontents
\let\manbreak\relax
\chapter{Some chapter}
\blinddocument
\blinddocument
\chapter{This is a really extra long \manbreak chapter name}
\end{document}
虽然我不知道如何在或\par
的定义中允许s,但可以使用类似的方法,这里重新定义,其中在目录中同样有一个定义,并且随后被ed。\l@chapter
\mw@seccntformat
\manbreak
\def\mw@seccntformat#1{#1\Manbreak}
\Manbreak
\relax
\documentclass{mwbk}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\usepackage{blindtext}
\makeatletter
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries \LARGE % added for large font for chapters
\advance\leftskip\@tempdima
\hskip -\leftskip %\@chapapp~ \par % added \@chapapp~ \par
#1\nobreak \raggedright % originally \hfil
%added for leaders (dots) in chapter in toc
%\xleaders\hbox{$\m@th
% \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
% mu$}\hfill%
%%%
\nobreak\hb@xt@\@pnumwidth{\hss \itshape \fbox{#2}}\par\vspace{12pt} % ADDED VSPACE
\penalty\@highpenalty
\endgroup
\fi}
%for mwbk
\def\mw@seccntformat#1{#1\Manbreak} % para tirar o ponto após número do capítulo
\renewcommand*\chapter@toc{%
\ifHeadingNumbered\typeout{\@chapapp\space\thechapter.}\fi
\addcontentsline{toc}{chapter}{%
\ifHeadingNumbered
\mw@seccntformat{\color{ForestGreen}\@chapapp\ \HeadingNumber}%
\fi
\color{yellow}\hfill\HeadingTOCText\hfill}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
}
\makeatother
\begin{document}
\def\Manbreak{\\\mbox{}}
\def\manbreak{\hfill\hfill\\\mbox{}\hfill}
\tableofcontents
\let\manbreak\relax
\let\Manbreak\relax
\chapter{Some chapter}
\blinddocument
\blinddocument
\chapter{This is a really extra long \manbreak chapter name}
\end{document}