`\titletoc`,格式化`\dottedcontents`:章节编号的颜色

`\titletoc`,格式化`\dottedcontents`:章节编号的颜色

经过多次尝试,我发现在使用和\thechapter时,仅设置颜色编号会出现问题。我实现了以下操作,但您可以看出章节编号重复了。有没有办法调用以避免这种情况?titletoc\dottedcontents\thecontentslabel

提前致谢

在此处输入图片描述

\documentclass{book}
\usepackage[newparttoc]{titlesec}

\usepackage[dvipsnames]{xcolor}
   \definecolor{myred}{RGB}{239, 0, 0}
   \definecolor{myblue}{RGB}{0,0,200}
\PassOptionsToPackage{pdfpages}{xcolor}

\usepackage{titletoc}
\titlecontents{part}[0pt]{\large\bfseries}
{\contentslabel[\color{myred} \thecontentslabel]{1.5em}}
{}
{\hfill\contentspage}

\dottedcontents{chapter}[2em]{\large\bfseries}
{\contentslabel[{\color{myblue}\thecontentslabel}]{2em}}{}



\begin{document}
 \tableofcontents
    \part{Trial name of Part}
    this is a blind text

    \chapter{Trial chapter}
    this is more blind text

    \section{Trial section}
\end{document}

答案1

您误用了\dottedcontents,其语法与 相同\titlecontents。以下是使用后一个命令的解决方案:

\documentclass{book}
\usepackage[showframe]{geometry}

\usepackage[newparttoc] {titlesec}
\titleformat{\part}[display]
{\Huge\fontsize{30pt}{60pt}\filcenter}{\partname{} \color{myred}\thepart}{0em}
\makeatother
\usepackage{titletoc}
\usepackage[dvipsnames, pdfpages]{xcolor}
   \definecolor{myred}{RGB}{239, 0, 0}
   \definecolor{myblue}{RGB}{0,0,200}
\titlecontents{part}[2.2em]{\Large\bfseries}
{\contentslabel[\color{myred} \thecontentslabel]{1.35em}}
{}
{\hfill\contentspage}[\addvspace{1ex}]
%
\titlecontents{chapter}[2.2em]{\large\bfseries}
{\contentslabel[{\color{myblue}\thecontentslabel}]{1em}}
{}
{\titlerule*[1pc]{.}\contentspage}[\addvspace{0.6ex}]
%
\titlecontents{section}[2.83em]{}
{\contentslabel[{\thecontentslabel}]{1.9em}}
{}
{\titlerule*[1pc]{.}\contentspage}[\addvspace{0.6ex}]

\begin{document}\setcounter{part}{3}
 \tableofcontents
    \part{Trial name of Part}
    this is a blind text

    \chapter{Trial chapter}
    this is more blind text

    \section{Trial section}

\end{document} [1.5em] 

在此处输入图片描述

相关内容