# How to place the chapter number behind the chapter title in KOMA script

I have the following layout for my chapter title and number:

I reached this using the following code:

\renewcommand*{\chapterformat}{%
\fontsize{60}{68}\selectfont\color{Gray}\thechapter\autodot\enskip}

\addtokomafont{chapter}{%
\renewcommand*{\raggedsection}{\raggedleft}}


What is the best way to move the chapter number (2 in this case) to the right end of the same line, so that it overlaps with the chapter title? (I want the title to be on top). If possible, I want the method to integrate well with KOMA script, for example by redefining \chapterformat like I did above.

## 3 Answers

You mean like this?

That doesn't look good, does it?

At the very least, I would do something like this:

\renewcommand*{\chapterformat}{%
\rlap{\makebox[\linewidth][r]{\colorbox{ltGray}{\fontsize{60}{68}\selectfont\color{Gray}\thechapter\autodot}}}}

\addtokomafont{chapter}{%
\renewcommand*{\raggedsection}{\raggedleft\rightskip1.2em\hfill}}


Disclaimer: I'm not a designer!

• Hello Stephan, Thank's for the solution. The first example indeed doesn't look good, but at least I can experiment now to find something better looking. – janoliver Apr 2 '12 at 14:28

Here is one way of obtaining the requested output via a patch of \@@makechapterhead (using etoolbox). \@@makechapterhead prints the actual chapter heading (chapter number + title) in scrbook.

\documentclass{scrbook}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{fix-cm}% http://ctan.org/pkg/fix-cm
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox

\renewcommand*{\chapterformat}{%
\fontsize{60}{68}\selectfont\color{black!50}\thechapter}% \autodot\enskip

\makeatletter
% Remove \chapterformat from \@@makechapterformat
\patchcmd{\@@makechapterhead}% <cmd>
{\chapterformat}% <search>
{}% <replace>
{}{}% <success><failure>
% Reinsert \chapterformat  modify heading layout
\patchcmd{\@@makechapterhead}% <cmd>
{\size@chapter{#1}}% <search>
{\ooalign{\hss\chapterformat\cr\size@chapter{#1}}}% <replace>
{}{}% <success><failure>
\makeatother

\addtokomafont{chapter}{%
\renewcommand*{\raggedsection}{\raggedleft}}
\begin{document}
\setcounter{chapter}{1}% Just for this example
\chapter{Text elements}
In this chapter, some textual elements are shown, like figures,
tables, lists, equations, etc. Also, bananas.
\end{document}


The first patch removes the typesetting of the chapter number (done via \chapterformat). The second patch re-inserts \chapterformat and overlays the title using \ooalign. For a quick course on \ooalign, see \subseteq + \circ as a single symbol ("open subset").

Since version 3.19 KOMA-Script provides the command \chapterlinesformat to define the format of chapters without prefix lines. You can redefine this command, \chapterformat and \raggedchapter to get something like

Code:

\documentclass{scrbook}
\usepackage{lmodern}
\usepackage{xcolor}

\renewcommand\raggedchapter{\raggedleft}
\renewcommand*{\chapterformat}{%
\fontsize{60}{68}\selectfont\textcolor{lightgray}{\thechapter}}

\makeatletter
\renewcommand\chapterlinesformat[3]{%
\ifstr{#1}{chapter}
{\raggedleft\makebox[0pt][r]{\smash{#2}}\makebox[0pt][r]{\parbox[t]{\textwidth}{\raggedchapter#3}}\par\nobreak}%
{\@hangfrom{#2}{#3}}% original definition for other commands with style=chapter
}
\makeatother

\usepackage{blindtext}
\begin{document}
\tableofcontents
\blinddocument
\chapter{Text elements}
In this chapter, some textual elements are shown, like figures,
tables, lists, equations, etc. Also, bananas.
\end{document}


Update because of a comment:

To place the chapter number in the margin I would use

\makeatletter
\renewcommand\chapterlinesformat[3]{%
\ifstr{#1}{chapter}
{\raggedright
\parbox[t]{\textwidth}{\raggedchapter#3}%
\makebox[0pt][l]{\smash{\enskip#2}}%
\par\nobreak
}%
{\@hangfrom{#2}{#3}}% original definition for other commands with style=chapter
}
\makeatother


\chapterlinesformat takes 3 arguments: the name of the sectioning level (#1), the formatted number (#2) and the formatted title (#3).

In the code segment chapter title (#3) takes the the whole text width. Its alignment is defined by \raggedchapter which is redefined in the example to \raggedleft. By default it would be \raggedsection which is defined as \raggedright. If the chapter title should be justified, then use \renewcommand\raggedchapter{}.

The chapter number (#2) is set in a box with width 0pt. So it is printed in the margin. \smash hides the height of the number. Therefore numbered and unnumbered (like TOC) chapter titles start at the same vertical position.

Example:

\documentclass{scrbook}
\usepackage{lmodern}
\usepackage{xcolor}

\renewcommand\raggedchapter{\raggedleft}
\renewcommand*{\chapterformat}{{%
\fontsize{60}{68}\selectfont\textcolor{lightgray}{\thechapter}}}

\makeatletter
\renewcommand\chapterlinesformat[3]{%
\ifstr{#1}{chapter}
{\raggedright
\parbox[t]{\textwidth}{\raggedchapter#3}%
\makebox[0pt][l]{\smash{\enskip#2}}%
\par\nobreak
}%
{\@hangfrom{#2}{#3}}% original definition for other commands with style=chapter
}
\makeatother

\usepackage{blindtext}
\begin{document}
\tableofcontents
\blinddocument
\chapter{In this chapter, some textual elements are shown, like figures,
tables, lists, equations, etc. Also, bananas.}
\end{document}

• how to change such that the number is in the margin (i.e. not overlapping the text)? – user855443 Aug 14 '18 at 13:10
• @user855443 See my updated answer. – esdd Aug 14 '18 at 22:23