tocloft
을 사용하면 ToC 내의 모든 입력 유형의 형식을 제어 할 수 있습니다. 챕터의 경우 \cftchapfont
, 섹션의 경우 \cftsecfont
및 하위 섹션은 \cftsubsecfont
입니다.
이하는 색을 변경하기 위해 ToC에 항목을 삽입하는 \authoredby{<name>}
을 제공합니다. 또한 저자 색상은 \defineauthorcolor{<name>}{<colour>}
을 사용하여 정의 할 수 있습니다.

\documentclass{book}
\usepackage{tocloft,xcolor}
\newcommand{\defineauthorcolor}[2]{%
\colorlet{author#1}{#2}% Create an author colour
\expandafter\def\csname authoredby#1\endcsname{% Create author colour settings
\renewcommand{\cftchapfont}{\bfseries\color{author#1}}% Chapter colour
\renewcommand{\cftsecfont}{\color{author#1}}% Section colour
\renewcommand{\cftsubsecfont}{\color{author#1}}}% Subsection colour
}
\makeatletter
\newcommand{\authoredby}[1]{\addtocontents{toc}{\protect\@nameuse{authoredby#1}}}%
\makeatother
\defineauthorcolor{A}{red}% Author A will be coloured red
\defineauthorcolor{B}{blue}% Author B will be coloured blue
\begin{document}
\tableofcontents
\authoredby{A}
\chapter{A chapter}
\authoredby{B}
\section{A section}
\subsection{A subsection}
\authoredby{A}
\section{Another section}
\subsection{Another subsection}
\authoredby{B}
\subsection{Yet another subsection}
\chapter{Another chapter}
\section{First section}
\section{Second section}
\section{Last section}
\authoredby{A}
\chapter{Last chapter}
\end{document}
상기 최소 예제의 .toc
은 다음과 같다 :
가
\@nameuse {authoredbyA}
\contentsline {chapter}{\numberline {1}A chapter}{3}
\@nameuse {authoredbyB}
\contentsline {section}{\numberline {1.1}A section}{3}
\contentsline {subsection}{\numberline {1.1.1}A subsection}{3}
\@nameuse {authoredbyA}
\contentsline {section}{\numberline {1.2}Another section}{3}
\contentsline {subsection}{\numberline {1.2.1}Another subsection}{3}
\@nameuse {authoredbyB}
\contentsline {subsection}{\numberline {1.2.2}Yet another subsection}{3}
\contentsline {chapter}{\numberline {2}Another chapter}{5}
\contentsline {section}{\numberline {2.1}First section}{5}
\contentsline {section}{\numberline {2.2}Second section}{5}
\contentsline {section}{\numberline {2.3}Last section}{5}
\@nameuse {authoredbyA}
\contentsline {chapter}{\numberline {3}Last chapter}{7}
\authoredby{<name>}
각각 사용 따라서 색을 전환 할 TOC에 \@nameuse{authoredby<name>}
를 삽입한다. 이 솔루션은 모든 수의 작성자 (두 명으로 제한되지는 않음)에서 작동합니다.
이 솔루션은 book
, report
및 article
문서 클래스에서 작동합니다.