1

Is there a way to:

  1. In the table of contents have the "Chapter" appear in a color other than black ?
  2. Is there a way to change the "section" color?

A 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}

The code generates the table of contents: contents

and the section: section

As can be seen in the code the colors of subsection, subsubsection, and paragraph can be changed. What the intent of the questions is is to determine a way to change the color of the "section" heading and to determine a way to have color specified for the word "chapter" in the table of contents.

  • Number 1) is confusing. I see no "Chapter" string in the table of contents. What exactly are you trying to do? Can you please explain in more detail? – Gonzalo Medina Jul 25 '15 at 20:38
  • In the case of \subsection etc. you... er... change the colour when specifying the title. In the case of \chapter and \section you don't. Am I missing something here? [Not that the use of manual markup in arguments to these commands is recommended - it is a bad idea. But it doesn't seem very mysterious why you get different colours when you ask for them and the standard colour when you don't.] – cfr Jul 25 '15 at 23:17
  • @cfr What is being asked is: given the above code: 1) how does one change how the chapter appears on the contents page, ie suppose is to appear in blue; 2) how does one change the color of the section both in the document and correspondingly on the contents page. Examples of changed color are the subsection and so on. – Leucippus Jul 26 '15 at 0:03
  • But what exactly is supposed to be in blue? Also, your preamble is definitely problematic. You ought not be using both inputenc and fontspec, and you probably ought not be using fontenc with fontspec. There is also not much point in loading lmodern and then overriding it with kpfonts. And you should have stretch in the spacing arguments to \titlespacing if you don't want things to get ugly. – cfr Jul 26 '15 at 0:22
2

This:

  • resolves conflicting preamble calls in favour of pdfTeX and kpfonts;
  • makes all chapter entries in the ToC blue, including the chapter number and title but not the number line or page;
  • makes all section entries in the ToC and all section headings magenta, including the section number and title;
  • tidies up a bit e.g. by eliminating unnecessary pagination commands and putting \frontmatter where it is probably intended to be.

Code:

\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}

The result is, in my considered view, an abomination but I realise that aesthetic preferences vary and are heavily dependent on sociological, historical and cultural factors. As long as I don't have to read the end result ;).

The ToC:

ToC

Note that the ToC is, itself, a chapter, so obviously appears in blue just like other chapters.

The section heading:

section heading

  • The code presented was minimal. There are plenty of fonts being used, hence the extra packages. The color coding is primarily to keep track of where the last work was on the document and what needs to be worked on. In the end the colors get removed for the final version which will make most happy. As always seems to be the issues of packages or designer missing something and thus questions get asked. Often good responces are presented and can be learned from so...thanks. – Leucippus Jul 26 '15 at 4:47
  • @Leucippus No, really. It was not minimal. It was not even consistent. And it is one thing to use several fonts but there is no point in loading, say, lmodern and then loading kpfonts. And you can't use inputenc and fontspec together and probably shouldn't use fontspec and fontenc together. (You can use the latter in specific cases but, unless you really need them and know why, you don't want both packages.) But also, was the index essential to the question? Was titling or url? No. – cfr Jul 26 '15 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.