目录中的颜色

目录中的颜色

有人能帮帮我吗?

我希望将点着色为红色且加粗(而不是像照片中那样的普通黑色)。

非常感谢您的帮助。

\documentclass{report}

%%%%% Format font + page + langue
\usepackage[utf8x]{inputenc}
\usepackage[a4paper,top=3cm,bottom=2.5cm,left=2.5cm,right=2cm,marginparwidth=1.75cm,headheight=30pt]{geometry}

\usepackage[french]{babel}
\AddThinSpaceBeforeFootnotes
\FrenchFootnotes
\usepackage[T1]{fontenc}
\setlength{\parindent}{0cm}
\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1}
\usepackage[titletoc]{appendix}

%%%%% Table of contents
\setcounter{secnumdepth}{5} % seting level of numbering

\usepackage[colorlinks=true]{hyperref}
\usepackage{tocloft}
\newcommand{\Color}[1]{\hypersetup{linkcolor=#1}\color{#1}}
\renewcommand{\cftchapfont}{\Color{red}\large\bfseries}
\renewcommand{\cftsecfont}{\Color{blue}}
\renewcommand{\cftsubsecfont}{\Color{black}}
\renewcommand{\cftsubsubsecfont}{\Color{green}}
\renewcommand{\cftchappagefont}{\large\bfseries\Color{red}}
\renewcommand{\cftsecpagefont}{\Color{blue}}
\renewcommand{\cftsubsecpagefont}{\Color{black}}
\renewcommand{\cftsubsubsecpagefont}{\Color{green}}
\renewcommand{\cftchapleader}{\Color{red}\cftdotfill{\cftchapdotsep}}
\renewcommand{\cftsecleader}{\Color{blue}\cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsubsecleader}{\Color{black}\cftdotfill{\cftsubsecdotsep}}
\renewcommand{\cftsubsubsecleader}{\Color{green}\cftdotfill{\cftsubsubsecdotsep}}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

%%%%% Indentfirst
\usepackage{indentfirst}
\setlength{\parindent}{1cm}

\usepackage{libertine} 

\usepackage{lmodern}

\begin{document}
\tableofcontents


\chapter{name of chapter 1}
\section{section 1}
\subsection{subsection 1}
\subsubsection{sub sub section 1}
\section{section 2}

\newpage
\chapter{name of chapter 2}
\section{section 21}
\subsection{sub sec 2}
\section{section 22}


\end{document}

在此处输入图片描述

答案1

(在 OP 修改了自己的代码和查询后更新了代码和截图)

我相信您应该为读者提供清晰的视觉效果,包括 (a) 目录中分段标题使用哪种颜色,以及 (b) 超链接使用哪种颜色。

因此,我建议您hyperref使用选项加载包linktocpage,该选项仅将目录中的页码转换为超目标,并且 (b) 使用与目录中已使用的颜色不同的超链接颜色(红色、蓝色、黑色、绿色)。也许使用靛蓝?选择适合文档中所有链接的颜色,而不仅仅是目录中显示的链接。

  • 基本上,你应该尽一切努力帮助你的读者形成强大的巴甫洛夫反射:每次他们看到一个用“链接颜色”着色的对象时,他们都应该想用鼠标点击它。如果只有一种颜色喊出“我是超链接”,巴甫洛夫反射就会更强。

  • 相反,如果您让多种不同的颜色(在某些情况下包括黑色)与超链接对象兼容,您的读者将更慢地了解超目标是什么以及在哪里。换句话说:“如果一切都很特别,那么就没有什么是特别的”。在如何部署颜色来传达含义时要非常谨慎。

顺便说一下,hyperref应该加载包tocloftxcolor

在此处输入图片描述

\documentclass{report}
\usepackage[a4paper,top=3cm,bottom=2.5cm,left=2.5cm,
            right=2cm,marginparwidth=1.75cm,
            headheight=30pt]{geometry}

\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[svgnames]{xcolor} % for 'DarkGreen' color
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\usepackage{tocloft}
\renewcommand{\cftchapfont}{\color{red}\large\bfseries}
\renewcommand{\cftsecfont}{\color{blue}}
\renewcommand{\cftsubsecfont}{\color{black}}
\renewcommand{\cftsubsubsecfont}{\color{DarkGreen}}

\renewcommand{\cftchapleader}{\color{red}     \cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsecleader}{\color{blue}     \cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsubsecleader}{\color{black} \cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsubsubsecleader}{\color{DarkGreen} \cftdotfill{\cftsecdotsep}}

\renewcommand{\cftchappagefont}{\color{red}%\large\bfseries
   }
%\renewcommand{\cftsecpagefont}{\color{blue}}
%\renewcommand{\cftsubsecpagefont}{\color{black}}
%\renewcommand{\cftsubsubsecpagefont}{\color{DarkGreen}}


\usepackage[colorlinks=true,  
       linkcolor=Indigo, % or some other suitable color
       linktocpage]{hyperref}

\begin{document}
\tableofcontents

\chapter{Thoughts}
\section{Hello}
\subsection{World}
\subsubsection{Really!}
\end{document}

答案2

感谢 MWE!您需要使用这个答案的技巧, 我认为。

\documentclass{report}

%%%%% Format font + page + langue
\usepackage[utf8x]{inputenc}
\usepackage[a4paper,top=3cm,bottom=2.5cm,left=2.5cm,right=2cm,marginparwidth=1.75cm,headheight=30pt]{geometry}

\usepackage[french]{babel}
\AddThinSpaceBeforeFootnotes
\FrenchFootnotes
\usepackage[T1]{fontenc}
\setlength{\parindent}{0cm}
\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1}
\usepackage[titletoc]{appendix}

%%%%% Table of contents
\setcounter{secnumdepth}{5} % seting level of numbering
\setcounter{tocdepth}{5}
\usepackage[colorlinks=true]{hyperref}
\usepackage{tocloft}
\newcommand{\Color}[1]{\hypersetup{linkcolor=#1}\color{#1}}
\renewcommand{\cftchapfont}{\Color{black}\large\bfseries}
\renewcommand{\cftsecfont}{\Color{blue}}
\renewcommand{\cftsubsecfont}{\Color{red}}
\renewcommand{\cftsubsubsecfont}{\Color{green}}
\renewcommand{\cftchappagefont}{\Color{black}}
\renewcommand{\cftsecpagefont}{\Color{blue}}
\renewcommand{\cftsubsecpagefont}{\Color{red}}
\renewcommand{\cftsubsubsecpagefont}{\Color{green}}
\renewcommand{\cftsecleader}{\Color{blue}\cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsubsecleader}{\Color{red}\cftdotfill{\cftsubsecdotsep}}
\renewcommand{\cftsubsubsecleader}{\Color{green}\cftdotfill{\cftsubsubsecdotsep}}
\renewcommand{\cftchapleader}{\large\bfseries\color{red}\cftdotfill{\cftdotsep}}
\renewcommand{\cftchappagefont}{\large\bfseries}
\hypersetup{%
colorlinks=true,% switch on coloured instead of framed links
linkcolor=blue,% main link color (e.g. for the ToC)
filecolor=magenta,% color of links to external files
urlcolor=red,% color to external URLs
}    
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

%%%%% Indentfirst
\usepackage{indentfirst}
\setlength{\parindent}{1cm}

\usepackage{libertine} 

\usepackage{lmodern}
%   uncomment these if you want to have the actual chapter font larger
%   \usepackage{titlesec}
%   \titleformat{\chapter}
%   {\normalfont\Huge\bfseries}{\thechapter}{1em}{}    
\begin{document}
\tableofcontents


\chapter{name of chapter 1}
\section{section 1}
\subsection{subsection 1}
\subsubsection{sub sub section 1}
\section{section 2}

\newpage
\chapter{name of chapter 2}
\section{section 21}
\subsection{sub sec 2}
\section{section 22}

\end{document}

在此处输入图片描述

相关内容