1

I'm using the scrbook class to write a document because of its high flexibility. The problem is when I tried to customize my chapters I succeeded in changing only the mainmatter chapters, but for \tableofcontents, \listoffigures, and \listoftables I couldn't do the same. What I need to add is a simple rule under the titles of these items as in following picture:

enter image description here

Most answers I have found rely on the titlesec package, which is not fully compatible with KOMA script and it will affect all chapters that are already well customized. I like using TiKZ for its power and high quality. Currently, I used \renewcommand*{\chapterformat} for customizing my chapters. Any idea how to do this for the \frontmatter pages? Thank you.

\documentclass[fontsize=12pt,
               twoside=false,%
               toc=listof,%
               toc=bibliography,%
               chapterprefix=true,%
               captions=tableheading,%
               numbers=noenddot]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{newtxtext,newtxmath}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{tikz,calc}  
\usetikzlibrary{calc,decorations.pathreplacing}
\usepackage[titletoc]{appendix}

\addtokomafont{sectioning}{\rmfamily}
\addtokomafont{chapter}{\raggedleft\linespread{1}}
\usepackage[headsepline]{scrpage2}

\renewcommand*{\chapterformat}{\normalfont%
              {\fontsize{20}{30}\scshape\chapappifchapterprefix{}}
              {\fontsize{80}{30}\selectfont\thechapter}%
              \tikz{\coordinate(h);
              \draw[overlay,remember picture,line width=1.5pt]%
              ([yshift=-07pt]h)--++(-150mm,0)%
}}%

\renewcommand{\contentsname}{Table of Contents}

\begin{document}
\frontmatter
\setstretch{1.62}
\pagestyle{plain}
\chapter{Dedication}        %====== Dedication
\chapter{Acknowledgments}   %====== Acknowledgments
\chapter{Abstract}          %====== Abstract
\tableofcontents            %====== Table of Contents
\listoffigures              %====== List of Figures
\listoftables               %====== List of Tables
\chapter{Abbreviations}     %====== List of Abbreviations
\mainmatter
\chapter{Chapter1}  
\chapter{Chapter2}  
\chapter{Chapter3}      
\appendix
\chapter{Appendix A}    
\backmatter
\chapter{References}
\end{document}
2

You could load etoolbox and change \chapterheadendvskip to insert the line in chapter titles outside of mainmatter:

\usepackage{etoolbox}
\makeatletter
\preto{\chapterheadendvskip}{%
  \if@mainmatter\else% only outside mainmatter
    \vspace{-\baselineskip}\hfill%
    \tikz{\coordinate(h);%
      \draw[overlay,remember picture,line width=1.5pt]%
        ([yshift=-7pt]h)--++(-150mm,0);}%
    \par\fi%
}
\makeatother

enter image description here

Code:

Note, that the package scrpage2 is outdated. The successor is scrlayer-scrpage.

\documentclass[fontsize=12pt,
               twoside=false,%
               toc=listof,%
               toc=bibliography,%
               chapterprefix=true,%
               captions=tableheading,%
               numbers=noenddot]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{newtxtext,newtxmath}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing}
\usepackage[titletoc]{appendix}

\addtokomafont{sectioning}{\rmfamily}
\addtokomafont{chapter}{\linespread{1}}
\renewcommand\raggedchapter{\raggedleft}
\usepackage[headsepline]{scrlayer-scrpage}
\KOMAoptions{onpsinit=\linespread{1}}

\renewcommand*{\chapterformat}{\normalfont%
              {\fontsize{20}{30}\scshape\chapappifchapterprefix{}}
              {\fontsize{80}{30}\selectfont\thechapter}%
              \tikz{\coordinate(h);
              \draw[overlay,line width=1.5pt]%
              ([yshift=-7pt]h)--++(-150mm,0);%
}}%

\usepackage{etoolbox}
\makeatletter
\preto{\chapterheadendvskip}{%
  \if@mainmatter\else% only outside mainmatter
    \vspace{-\baselineskip}\hfill%
    \tikz{\coordinate(h);%
      \draw[overlay,remember picture,line width=1.5pt]%
        ([yshift=-7pt]h)--++(-150mm,0);}%
    \par\fi%
}
\makeatother

\usepackage[english]{babel}
\renewcaptionname{english}{\contentsname}{Table of Contents}

\usepackage{blindtext}% dummy text
%\usepackage{showframe}% to show the page layout

\begin{document}
\frontmatter
\pagestyle{plain}
\setstretch{1.62}
\chapter{Dedication}        %====== Dedication
\textbf{\KOMAScriptVersion}

\blindtext
\chapter{Acknowledgments}   %====== Acknowledgments
\blindtext
\chapter{Abstract}          %====== Abstract
\blindtext
\tableofcontents            %====== Table of Contents
%\listoffigures              %====== List of Figures
%\listoftables               %====== List of Tables
%\chapter{Abbreviations}     %====== List of Abbreviations
\mainmatter
\pagestyle{scrheadings}
\blinddocument
\appendix
\blinddocument
\backmatter
\chapter{References}
\blindtext
\end{document}

You can also left-justify the chapters outside mainmatter as asked in a comment. Use

\makeatother
\renewcommand\raggedchapter{\if@mainmatter\raggedleft\else\fi}
\makeatother

or

\makeatother
\renewcommand\raggedchapter{\if@mainmatter\raggedleft\else\raggedright\fi}
\makeatother

But then rule under this chapter titles should also be left aligned:

\usepackage{etoolbox}
\makeatletter
\preto{\chapterheadendvskip}{%
  \if@mainmatter\else% only outside mainmatter
    \vspace{-\baselineskip}\noindent%
    \tikz{\coordinate(h);%
      \draw[overlay,remember picture,line width=1.5pt]%
        ([yshift=-7pt]h)--++(150mm,0);}%
    \par\fi%
}
\makeatother

enter image description here

Code:

\documentclass[fontsize=12pt,
               twoside=false,%
               toc=listof,%
               toc=bibliography,%
               chapterprefix=true,%
               captions=tableheading,%
               numbers=noenddot]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{newtxtext,newtxmath}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing}
\usepackage[titletoc]{appendix}

\addtokomafont{sectioning}{\rmfamily}
\addtokomafont{chapter}{\linespread{1}}

\usepackage[headsepline]{scrlayer-scrpage}
\KOMAoptions{onpsinit=\linespread{1}}

\renewcommand*{\chapterformat}{\normalfont%
              {\fontsize{20}{30}\scshape\chapappifchapterprefix{}}
              {\fontsize{80}{30}\selectfont\thechapter}%
              \tikz{\coordinate(h);
              \draw[overlay,line width=1.5pt]%
              ([yshift=-7pt]h)--++(-150mm,0);%
}}%

\usepackage{etoolbox}
\makeatletter
\preto{\chapterheadendvskip}{%
  \if@mainmatter\else% only outside mainmatter
    \vspace{-\baselineskip}\noindent%
    \tikz{\coordinate(h);%
      \draw[overlay,remember picture,line width=1.5pt]%
        ([yshift=-7pt]h)--++(150mm,0);}%
    \par\fi%
}
\renewcommand\raggedchapter{\if@mainmatter\raggedleft\else\fi}
\makeatother

\usepackage[english]{babel}
\renewcaptionname{english}{\contentsname}{Table of Contents}

\usepackage{blindtext}% dummy text
%\usepackage{showframe}% to show the page layout

\begin{document}
\frontmatter
\pagestyle{plain}
\setstretch{1.62}
\chapter{Dedication}        %====== Dedication
\textbf{\KOMAScriptVersion}

\blindtext
\chapter{Acknowledgments}   %====== Acknowledgments
\blindtext
\chapter{Abstract}          %====== Abstract
\blindtext
\tableofcontents            %====== Table of Contents
%\listoffigures              %====== List of Figures
%\listoftables               %====== List of Tables
%\chapter{Abbreviations}     %====== List of Abbreviations
\mainmatter
\pagestyle{scrheadings}
\blinddocument
\appendix
\blinddocument
\backmatter
\chapter{References}
\blindtext
\end{document}
2
  • (+1) Thank you @esdd, it works perfect. Can I also left-justify the titles without affecting the main chapters?
    – AboAmmar
    Jun 2 '15 at 16:40
  • 1
    Yes, this is possible. See my extended answer
    – esdd
    Jun 2 '15 at 19:30

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.