为目录和章节标题添加颜色

为目录和章节标题添加颜色

有没有办法:

  1. 目录中的“章节”是否以黑色以外的颜色显示?
  2. 有没有办法改变“部分”的颜色?

一位 MWE 表示:

\documentclass[12pt,twoside]{memoir} 
%-- Fonts and related
%\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{url}
\usepackage{kpfonts}
%-- Color and designs
\usepackage[usenames,dvipsnames,svgnames,x11names]{xcolor}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage{makeidx}
\usepackage{titling}
\usepackage{graphicx}

\usepackage{lipsum}
\usepackage{kantlipsum}


%--------------------------------------------------------
%--- Commands for the Fancy Chapter headdings
%--------------------------------------------------------
\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{{\color{yellow}{\thechapter\ }}}}{0pt} %Color of chapter number in bubble
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=LightSkyBlue] (0,0) rectangle %Color of rectangle
          (\paperwidth,3cm);
          \draw[ultra thick, Red] (0,0) -- (100,0); %Color of line under large rectangle
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue] %Color of bbubble
              {\color{OrangeRed2}\chapterlabel#1}; %Color of chapter word in bubble
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}
%--------------------------------------------------------
%--- Commands for the Fancy Chapter headdings
%--------------------------------------------------------

\setcounter{tocdepth}{4} %shows all levels incl. paragraph
\makeindex
%--------------------------------------------------------
%--- Document Beginning
%--------------------------------------------------------
\begin{document}

\setcounter{page}{1}
\pagenumbering{roman}

\tableofcontents
\frontmatter
\newpage

\pagenumbering{arabic}
\mainmatter


%------------------------------------------
%--- First chapter
%------------------------------------------
\chapter{Dummy chapter}
\kant[2]

\section{Dummy section}
\lipsum[2]

\subsection{{\color{SeaGreen}{Dummy subsection}}}
\lipsum[2]

\subsubsection{{\color{Tomato}{Dummy subsubsection}}}
\lipsum[2]

\paragraph{{\color{CadetBlue}{Dummy paragraph}}}
\lipsum[2]


%--------------------------------------------------------
%--- Document Ending
%--------------------------------------------------------
\end{document}

代码生成目录: 内容

以及以下部分: 部分

从代码中可以看出,小节、子小节和段落的颜色可以更改。问题的目的是确定如何更改“节”标题的颜色,以及如何为目录中的单词“章”指定颜色。

答案1

这:

  • 解决了有利于 pdfTeX 和 的冲突前言调用kpfonts
  • 将目录中的所有章节条目变为蓝色,包括章节号和标题,但不包括行号或页码;
  • 将目录中的所有章节条目和所有章节标题(包括章节编号和标题)设为洋红色;
  • \frontmatter通过消除不必要的分页命令并将其放置在可能需要的位置,来进行一些整理。

代码:

\documentclass[12pt,twoside]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{url}
\usepackage{kpfonts}
\usepackage[usenames,dvipsnames,svgnames,x11names]{xcolor}
\usepackage{tikz}
\usepackage[explicit]{titlesec}% this ought to use memoir's facilities
\usepackage{makeidx}
\usepackage{titling}

\usepackage{lipsum}
\usepackage{kantlipsum}

\renewcommand*\cftchapterfont{\color{blue}}
\renewcommand*\cftsectionfont{\color{magenta}}
\setsecheadstyle{\color{magenta}\Large\bfseries}

% this ought to be done using memoir's facilities
\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{{\color{yellow}{\thechapter\ }}}}{0pt} %Color of chapter number in bubble
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=LightSkyBlue] (0,0) rectangle %Color of rectangle
          (\paperwidth,3cm);
          \draw[ultra thick, Red] (0,0) -- (100,0); %Color of line under large rectangle
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue] %Color of bbubble
              {\color{OrangeRed2}\chapterlabel#1}; %Color of chapter word in bubble
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}

\setcounter{tocdepth}{4} %shows all levels incl. paragraph
\makeindex
\begin{document}

\frontmatter
\tableofcontents

\mainmatter

\chapter{Dummy chapter}
\kant[2]

\section{Dummy section}
\lipsum[2]

\subsection{{\color{SeaGreen}{Dummy subsection}}}
\lipsum[2]

\subsubsection{{\color{Tomato}{Dummy subsubsection}}}
\lipsum[2]

\paragraph{{\color{CadetBlue}{Dummy paragraph}}}
\lipsum[2]
\end{document}

在我看来,这个结果令人厌恶,但我意识到审美偏好各不相同,并且在很大程度上取决于社会、历史和文化因素。只要我不必阅读最终结果 ;)。

目录:

目录

请注意,目录本身就是一个章节,因此显然与其他章节一样以蓝色显示。

章节标题:

章节标题

相关内容