2

I am using this https://github.com/derric/cleanthesis template, but its combining titlesec and KOMA script which I would like to avoid.

Heres an example of the chapter style:

\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}

\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}

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

\begin{document}

\chapter{A test chapter with a long title that will span two lines}
\lipsum[4]

\end{document}

enter image description here

Is there a way I can reproduce the colored line and chapter number with chapter name linebreak using only KOMA script?

  • What should happen if the number has two or three digits? – Ulrike Fischer Apr 5 '18 at 11:53
  • Hm good question, for my case its not going to be more than one digit so esdd answer is perfect. – voiDnyx Apr 6 '18 at 11:43
2

Maybe the following helps:

\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}

\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}

\RedeclareSectionCommand[
  beforeskip=-1sp
]{chapter}

\makeatletter
\renewcommand\chapterlinesformat[3]{%
  \ifstr{#1}{chapter}
    {%
      \parbox[b][\ht\strutbox]{\textwidth}{%
        \parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#3}%
        \makebox[3em][r]{%
          \hfill
          #2%
        }%
      }%
    }{\@hangfrom{#2}{#3}}% <- original definition for other levels
}
\makeatother
\renewcommand\chapterformat{%
  \textcolor{ctcolorchapterline}{\rule[-5pt]{2pt}{5cm}}%
  \quad
  {\fontsize{60}{60}\selectfont\textcolor{ctcolorchapternum}{\thechapter}}%
}
\begin{document}
\tableofcontents
\chapter{A test chapter with a long title that will span two lines}
\lipsum[4]
\chapter{Chapter with short title}
\lipsum
\end{document}

enter image description here

Note that this suggestion is limited to one digit numbers (like your MWE).


Update regarding the usage appendixprefix=true

As mentioned in your comment below you want to set appendixprefix=true. So I assume that you want to use the default layout for chapter titles in appendix. Then you have to change the redefinition of \chapterformat to

\renewcommand\chapterformat{%
  \IfUsePrefixLine{%
    \mbox{\chapappifchapterprefix{\nobreakspace}\thechapter\autodot\enskip}%
  }{%
    \textcolor{ctcolorchapterline}{\rule[-5pt]{2pt}{5cm}}%
    \quad
    {\fontsize{60}{60}\selectfont\textcolor{ctcolorchapternum}{\thechapter}}%
  }%
}

enter image description here

  • There seems to be a problem with appendix chapters when I use this and \appendix with appendixprefix=true for my documentclass, do you happen to know how to fix this? – voiDnyx Apr 12 '18 at 13:36
  • 1
    @voiDnyx See my updated answer. If it does not solve your issue, then please ask a follow up question and explain what the desired layout for chapters in appendix is. Maybe \chapterlineswithprefixformat must be redefined too. – esdd Apr 13 '18 at 9:50
  • Im sorry, its working perfectly fine without the appendixprefix option. I had the wrong idea that option was responsible for sections starting with letters. Turns out its for something completely different :) – voiDnyx Apr 16 '18 at 11:53

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.