1

I am trying to customize the chapter formats in different matter of the document. How can I obtain a blue bar under the chapter headers from the frontmatter ? This is the best I obtained so far...

Note: If you don't have arial font, replace by anything so you can run the example.

\documentclass[
    a4paper,
    oneside,
    11pt,
    cleardoublepage=empty,
    numbers=noenddot,
    titlepage,
    toc=bibliography,
    chapterprefix=true,
    headings=chapterprefix,
    toc=index,
]{scrbook}

\usepackage{textcase}

% fonts \RequirePackage{fontspec} %\newfontfamily\AdobeCaslonPro{Adobe Caslon Pro} %\newfontfamily\ZapfHumnstBT{ZapfHumnst BT} %\newfontfamily\ZapfHumnstDmBT{ZapfHumnst Dm BT} %\newfontfamily\ZapfHumnstUltBT{ZapfHumnst Ult BT} \newfontfamily\AdobeCaslonPro{arial} \newfontfamily\ZapfHumnstBT{arial} \newfontfamily\ZapfHumnstDmBT{arial} \newfontfamily\ZapfHumnstUltBT{arial}

% colors \RequirePackage[usenames,dvipsnames]{xcolor} \definecolor{darkbluejebrack}{RGB}{0,141,198} \definecolor{mediumbluejebrack}{RGB}{0,171,238} \definecolor{lightbluejebrack}{RGB}{114,214,247}

\newcommand{\titleprefixfontsize}{\fontsize{30}{30}} \newcommand{\titlefontsize}{\fontsize{20}{20}}

\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}} \newcommand{\titlesubbar}{{\color{lightbluejebrack} \rule[.4\baselineskip]{\linewidth}{1.2mm}}}

%% This is for the spacing around chapter (above and under) \RedeclareSectionCommand[innerskip=0pt]{chapter}

\makeatletter \newcommand\matter@switch{} \addtokomafont{chapterentry}{\matter@switch} \g@addto@macro\frontmatter{% \addtocontents{toc}{% \protect\renewcommand\protect\matter@switch{\normalfont\itshape}% }% \setkomafont{chapter}{\titleprefixfontsize \normalfont \bfseries \ZapfHumnstDmBT \MakeTextUppercase}% } \g@addto@macro\mainmatter{% \addtocontents{toc}{% \protect\renewcommand\protect\matter@switch{}% }% \setkomafont{chapter}{\titlefontsize \AdobeCaslonPro \bfseries}% \setkomafont{chapterprefix}{\titleprefixfontsize \normalfont \bfseries \ZapfHumnstDmBT \MakeTextUppercase} % Add a blue line under "CHAPTER"
\renewcommand\chapterlineswithprefixformat[3]{% #2\nobreak\vspace{-.15cm}% \titlesubbar\par\nobreak%% \Ifstr{#2}{}{}{\kern-\dp\strutbox} #3% } }

\begin{document} \frontmatter \tableofcontents \chapter{Preface} \chapter{Acknowledgements} \mainmatter \chapter{First Chapter} \chapter{Second Chapter} \end{document}

  • You could do this similar to my answer here, redefining \chapterlineswithprefixformat instead of \sectionlinesformat. Note, that the commands have a different number of arguments. For another example see also: “How to put a horizontal line above and below chapter headings” in the KOMA-Script Wiki. – cabohah Jan 18 '23 at 07:10
  • Just a note: If the font does not matter, it would be better to remove all font code or replace it by a free font available in TeX Live and MiKTeX independent from the OS. It is always a bit demotivating when the first LaTeX run ends in an avoidable error message. – cabohah Jan 18 '23 at 07:18

1 Answers1

1

You can add your \titlesubbar also to a redefined \chapterlineswithprefixformat inside the \frontmatter addon:

\documentclass[
    a4paper,
    oneside,
    11pt,
    cleardoublepage=empty,
    numbers=noenddot,
    titlepage,
    toc=bibliography,
    chapterprefix=true,
    headings=chapterprefix,
    toc=index,
]{scrbook}

\usepackage{textcase}

% colors \RequirePackage[usenames,dvipsnames]{xcolor} \definecolor{darkbluejebrack}{RGB}{0,141,198} \definecolor{mediumbluejebrack}{RGB}{0,171,238} \definecolor{lightbluejebrack}{RGB}{114,214,247}

\newcommand{\titleprefixfontsize}{\fontsize{30}{30}} \newcommand{\titlefontsize}{\fontsize{20}{20}}

\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}} \DeclareRobustCommand{\titlesubbar}{{\color{lightbluejebrack} \rule[.4\baselineskip]{\linewidth}{1.2mm}}}

%% This is for the spacing around chapter (above and under) \RedeclareSectionCommand[innerskip=0pt]{chapter}

\makeatletter \newcommand\matter@switch{} \addtokomafont{chapterentry}{\matter@switch} \g@addto@macro\frontmatter{% \addtocontents{toc}{% \protect\renewcommand\protect\matter@switch{\normalfont\itshape}% }% \setkomafont{chapter}{\titleprefixfontsize \normalfont \bfseries \MakeTextUppercase}% \renewcommand\chapterlineswithprefixformat[3]{% {#2#3}% original definition \IfArgIsEmpty{#2}{\vskip-\dp\strutbox\titlesubbar\par\nobreak}{}% added } } \g@addto@macro\mainmatter{% \addtocontents{toc}{% \protect\renewcommand\protect\matter@switch{}% }% \setkomafont{chapter}{\titlefontsize \bfseries}% \setkomafont{chapterprefix}{\titleprefixfontsize \normalfont \bfseries
\MakeTextUppercase} % Add a blue line under "CHAPTER"
\renewcommand\chapterlineswithprefixformat[3]{% #2\nobreak\vspace{-.15cm}% \titlesubbar\par\nobreak%% \Ifstr{#2}{}{}{\kern-\dp\strutbox} #3% } } \makeatother

\begin{document} \frontmatter \tableofcontents \chapter{Preface} \chapter{Acknowledgements} \mainmatter \chapter{First Chapter} \chapter{Second Chapter} \end{document}

not numbered chapter with line

Note: I've removed the fonts to make the example compile independent from OS and installed fonts and independent from the TeX engine.

Note also: Because \MakeTextUppercase is not a font command, using in the second argument of \setkomafont or \addtokomafont it outside the specification and therefore dangerous. IMHO it would be better to move it into the redefinition of \chapterlineswidthprefixformat:

\documentclass[
    a4paper,
    oneside,
    11pt,
    cleardoublepage=empty,
    numbers=noenddot,
    titlepage,
    toc=bibliography,
    chapterprefix=true,
    headings=chapterprefix,
    toc=index,
]{scrbook}

\usepackage{textcase}

% colors \RequirePackage[usenames,dvipsnames]{xcolor} \definecolor{darkbluejebrack}{RGB}{0,141,198} \definecolor{mediumbluejebrack}{RGB}{0,171,238} \definecolor{lightbluejebrack}{RGB}{114,214,247}

\newcommand{\titleprefixfontsize}{\fontsize{30}{30}\selectfont} \newcommand{\titlefontsize}{\fontsize{20}{20}\selectfont}

\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}} \DeclareRobustCommand{\titlesubbar}{{\color{lightbluejebrack} \rule[.4\baselineskip]{\linewidth}{1.2mm}}}

%% This is for the spacing around chapter (above and under) \RedeclareSectionCommand[innerskip=0pt]{chapter}

\makeatletter \newcommand\matter@switch{} \addtokomafont{chapterentry}{\matter@switch} \setkomafont{chapterprefix}{\titleprefixfontsize \normalfont \bfseries} \g@addto@macro\frontmatter{% \addtocontents{toc}{% \protect\renewcommand\protect\matter@switch{\normalfont\itshape}% }% \setkomafont{chapter}{\usekomafont{chapterprefix}}% } \g@addto@macro\mainmatter{% \addtocontents{toc}{% \protect\renewcommand\protect\matter@switch{}% }% \setkomafont{chapter}{\titlefontsize \bfseries}% }

% Add a blue line under "CHAPTER" resp. under the title \renewcommand\chapterlineswithprefixformat[3]{% \MakeTextUppercase{#2}% \if@mainmatter \nobreak% shouldn't be needed here \vspace{-.15cm}% \titlesubbar\par \nobreak% shouldn't be needed here #3% \else \MakeTextUppercase{#3}% \IfArgIsEmpty{#2}{\vskip-\dp\strutbox\titlesubbar\par\nobreak}{}% \fi } \makeatother

\begin{document} \frontmatter \tableofcontents \chapter{Preface} \chapter{Acknowledgements} \mainmatter \chapter{First Chapter} \chapter{Second Chapter} \end{document}

The notes about \nobreak are there, because \chapter should always start a new page and therefore inside a chapter title a page break should never happen. If is would be needed, you are in trouble with and without the \nobreak. ;-)

cabohah
  • 11,455