0

I would like to color my chapter title and number in red using titlesec but somehow cant get the color on the title itself to work. since its part of a big, nested thesis I dont have MWE, just the code to define the chapter. there must be the error somewhere... the design looks like this:

enter image description here

\colorlet{ctcolorchapterline}{red}
\colorlet{ctcolorchapternum}{red}

\newcommand\mychapformat[1]{%
  \parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#1}}
\titleformat{\chapter}[display]%
  {\usekomafont{chapter} }%
    {\textcolor{red}}%
  {\vspace{-3px}\raggedleft{%
    {\color{ctcolorchapterline}%
        \rule[-5pt]{1.5pt}{2.3cm}}\quad%
    {\color{ctcolorchapternum}
        \fontsize{60}{60}\selectfont\thechapter}%
    }%
  }%
  {-2.1em}%
  {\mychapformat}%
  [\phantomsection]

Merci A

3
  • What color should the title be? – egreg May 7 '18 at 13:52
  • 2
    By the way, it's not a good idea to use titlesec along with scrbook. – egreg May 7 '18 at 13:54
  • @egreg the color should be red. if you know a better way to achieve the design, I gladly use that. – aerioeus May 7 '18 at 14:11
0

Note that it is not recommended to use package titlesec together with a KOMA-Script class. But you have mentioned a big template (maybe based on package cleanthesis?). So it does not make sense for me to give a suggestion without titlesec.

You could use:

\documentclass{scrbook}
\usepackage{lmodern}
\usepackage{titlesec}
\usepackage{xcolor}
\usepackage{hyperref}
\colorlet{ctcolorchapterline}{red}
\colorlet{ctcolorchapternum}{red}
\colorlet{ctcolorchaptertext}{red}

\newcommand\mychapformat[1]{\parbox[t]{\dimexpr\textwidth-3em\relax}{\raggedright#1}}
\titleformat{\chapter}[display]%
  {\usekomafont{chapter}\color{ctcolorchaptertext}}%
  {\vspace{-3px}\raggedleft{%
    {\color{ctcolorchapterline}%
      \rule[-5pt]{1.5pt}{2.3cm}}\quad%
    {\color{ctcolorchapternum}
      \fontsize{60}{60}\selectfont\thechapter}%
    }%
  }%
  {-2.1em}%
  {\mychapformat}%

\usepackage{blindtext}
\begin{document}
\tableofcontents
\blinddocument
\end{document}

Result:

enter image description here

Or:

\documentclass{scrbook}
\usepackage{lmodern}
\usepackage{titlesec}
\usepackage{xcolor}
\usepackage{hyperref}
\colorlet{ctcolorchapterline}{red}
\colorlet{ctcolorchapternum}{red}
\colorlet{ctcolorchaptertext}{red}

\newcommand\mychapformat[1]{\parbox[t]{\dimexpr\textwidth-3em\relax}{\raggedright#1}}
\titleformat{\chapter}[display]%
  {\usekomafont{chapter}}%
  {\vspace{-3px}\raggedleft{%
    {\color{ctcolorchapterline}%
      \rule[-5pt]{1.5pt}{2.3cm}}\quad%
    {\color{ctcolorchapternum}
      \fontsize{60}{60}\selectfont\thechapter}%
    }%
  }%
  {-2.1em}%
  {\mychapformat}%
\addtokomafont{chapter}{\color{ctcolorchaptertext}}

\usepackage{blindtext}
\begin{document}
\tableofcontents
\blinddocument
\end{document}

The result for numbered chapters is the same as above, but the ToC title is colored red, too.

1
  • Merci, the colorlet{ctcolorchaptertext}{red} was my missing link... – aerioeus May 8 '18 at 8:34
0

try this:

\colorlet{ctcolorchapterline}{red}
\colorlet{ctcolorchapternum}{red}

\titleformat{\chapter}%
[display]%
{{\usekomafont{chapter}\color{red}}%
{\vspace{-3px}\raggedleft{{\color{ctcolorchapterline}\rule[-5pt]{1.5pt}%{2.3cm}}\quad        {\color{ctcolorchapternum}\fontsize{60}{60}\selectfont\thechapter}}}%
{-2.1em}%
{}%
[]

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.