在Latex中使用两种颜色自定义目录

在Latex中使用两种颜色自定义目录,latex,tableofcontents,latex-environment,Latex,Tableofcontents,Latex Environment,在我的文档中,我想在目录中使用两种颜色来区分两位作者的作品。比如说, 蓝色的章节和小节由作者X编写,红色的章节和小节由作者Y编写 在某些章节中,章节和小节由两位作者编写。例如,在第A章(蓝色) 第1节(蓝色)由X编写 第1.1小节(红色)和第2节(红色)由Y编写 最后,这些颜色只能在目录中更改,而不能在文件内容中更改 我怎样才能像那样定制?有人能帮上忙吗 提前感谢。您可以控制ToC中每个条目类型的格式。章节有\cftchapfont,章节有\cftsecfont,小节有\cftsecfo

在我的文档中,我想在目录中使用两种颜色来区分两位作者的作品。比如说,

  • 蓝色的章节和小节由作者X编写,红色的章节和小节由作者Y编写
在某些章节中,章节和小节由两位作者编写。例如,在第A章(蓝色)

  • 第1节(蓝色)由X编写
  • 第1.1小节(红色)和第2节(红色)由Y编写
最后,这些颜色只能在目录中更改,而不能在文件内容中更改

我怎样才能像那样定制?有人能帮上忙吗

提前感谢。

您可以控制ToC中每个条目类型的格式。章节有
\cftchapfont
,章节有
\cftsecfont
,小节有
\cftsecfont

下面提供由{}编写的
\authoredby,它在ToC中插入一个条目以更改颜色。此外,可以使用
\defineauthorcolor{}{}
定义作者颜色

上述最小示例的
.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{}
都会将
\@nameuse{authoredby}
插入到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}