![amsbook 类中的目录自定义](https://linux22.com/image/439178/amsbook%20%E7%B1%BB%E4%B8%AD%E7%9A%84%E7%9B%AE%E5%BD%95%E8%87%AA%E5%AE%9A%E4%B9%89.png)
是否可以定制目录按照所附屏幕截图所示?以下内容是必需的。
- 红色章节名称和页码
- 蓝色的章节名称和页码
- 章节/节标题和页码之间的点
这是需要定制的代码。
\documentclass{amsbook}
\usepackage{xpatch,fmtcount}
\usepackage[colorlinks=true]{hyperref}
\renewcommand{\sectionname}{Unit}
\renewcommand{\thechapter}{\ifnum\value{chapter}<10 0\fi\arabic{chapter}}
\makeatletter
% remove the period from the toc
\renewcommand{\tocsection}[3]{%
\indentlabel{\@ifnotempty{#2}{\ignorespaces#1 #2\quad}}#3} % was #2.\quad
\let\tocchapter\tocsection
\let\tocsubsection\tocsection
\let\tocparagraph\tocsection
\let\tocsubparagraph\tocsection
% remove the period from the section numbers
\renewcommand\@seccntformat[1]{%
\protect\textup{\protect\@secnumfont
\csname the#1\endcsname
\protect\enspace % was \@secnumpoint
}%
}
% remove the period after the titles
\patchcmd{\@sect}{\@addpunct.}{}{}{}
% fix the page style
\def\ps@headings{\ps@empty
\def\@evenhead{%
\setTrue{runhead}%
\normalfont\scriptsize
\hfil % <---- was \rlap{\thepage}\hfil
\def\thanks{\protect\thanks@warning}%
\leftmark{}{}\hfil}%
\def\@oddhead{%
\setTrue{runhead}%
\normalfont\scriptsize \hfil
\def\thanks{\protect\thanks@warning}%
\rightmark{}{}\hfil}% <--- was \hfil\llap{\thepage}
% taken from \ps@plain
\def\@oddfoot{\normalfont\scriptsize \hfil\thepage\hfil}%
\let\@evenfoot\@oddfoot
%
\let\@mkboth\markboth
\def\partmark{\@secmark\markboth\partrunhead\partname}%
\def\chaptermark{%
\@secmark\markboth\chapterrunhead{}}%
\def\sectionmark{%
\@secmark\markright\sectionrunhead\sectionname}%
}
\makeatother
\renewcommand{\thesection}{\padzeroes[2]{\decimal{chapter}}-\padzeroes[2]{\decimal{section}: }}
\begin{document}
\tableofcontents
\chapter{First}
\section{one}
\chapter{Second}
\section{two}
\section{three}
\chapter{Third}
\end{document}
答案1
这是三个要求的代码。
\documentclass{amsbook}
\usepackage{xpatch,fmtcount}
\usepackage{xcolor} % added
\usepackage{hyperref} %changed to control the colors in TOC
\hypersetup{
colorlinks,
linkcolor={red!50!black},
citecolor={blue!50!black},
urlcolor={blue!80!black}
}
\makeatletter
\global\def\param{}
% color of page numbers in TOC <<<<<<<<<<<<<<<<
\renewcommand{\@tocpagenum}[1]{\hss{\mdseries\ifx\param\empty\color{red}\else\color{blue}\fi #1}}
\renewcommand{\tocsection}[3]{% style of section in TOC <<<<<<<<<<
\global\def\param{section} \color{blue}
\indentlabel{\@ifnotempty{#2}{\ignorespaces#1\;#2\;}}#3\dotfill} % spaces, color and dots
\renewcommand{\tocchapter}[3]{%% style of chapter in TOC <<<<<<<<<<
\global\def\param{}\color{red}
\indentlabel{\@ifnotempty{#2}{\ignorespaces#1\;#2\enspace}}#3\dotfill} % spaces,color and dots
\let\tocsubsection\tocsection
\let\tocparagraph\tocsection
\let\tocsubparagraph\tocsection
\renewcommand{\sectionname}{Unit}
\renewcommand{\thechapter}{\ifnum\value{chapter}<10 0\fi\arabic{chapter}}
% remove the period from the section numbers
\renewcommand\@seccntformat[1]{%
\protect\textup{\protect\@secnumfont
\csname the#1\endcsname
\protect\enspace % was \@secnumpoint
}%
}
% remove the period after the titles
\patchcmd{\@sect}{\@addpunct.}{}{}{}
% fix the page style
\def\ps@headings{\ps@empty
\def\@evenhead{%
\setTrue{runhead}%
\normalfont\scriptsize
\hfil % <---- was \rlap{\thepage}\hfil
\def\thanks{\protect\thanks@warning}%
\leftmark{}{}\hfil}%
\def\@oddhead{%
\setTrue{runhead}%
\normalfont\scriptsize \hfil
\def\thanks{\protect\thanks@warning}%
\rightmark{}{}\hfil}% <--- was \hfil\llap{\thepage}
% taken from \ps@plain
\def\@oddfoot{\normalfont\scriptsize \hfil\thepage\hfil}%
\let\@evenfoot\@oddfoot
%
\let\@mkboth\markboth
\def\partmark{\@secmark\markboth\partrunhead\partname}%
\def\chaptermark{%
\@secmark\markboth\chapterrunhead{}}%
\def\sectionmark{%
\@secmark\markright\sectionrunhead\sectionname}%
}
\makeatother
\renewcommand{\thesection}{\padzeroes[2]{\decimal{chapter}}-\padzeroes[2]{\decimal{section}:}}% extra space removed <<<<
\begin{document}
\tableofcontents
\chapter{First}
\section{one}
\chapter{Second}
\section{two}
\section{three}
\chapter{Third}
\end{document}