# Chapter and section number in margin and align chapter prefix with text in scrbook

I try to customize my chapter headings, without using additional packages like titlesec, as I'd like to avoid incompatibilities with all the other stuff around.

I almost have what I want:

\documentclass[
fontsize=12pt,
BCOR=15mm,
DIV=15,
twoside=true,
open=right,
chapterprefix = true,
]{scrbook}

\usepackage{fontspec}
\setmainfont[Numbers = OldStyle,Ligatures = TeX,SmallCapsFeatures = {Renderer=Basic}]{Minion Pro}

\usepackage{anyfontsize}
\setkomafont{chapter}{\normalfont\Huge}
\renewcommand*{\chapterformat}{%
{\fontsize{20}{30}\scshape\chapappifchapterprefix{\nobreakspace}}
\fontsize{120}{30}\selectfont\thechapter\autodot\enskip}
\renewcommand*{\raggedchapter}{\raggedleft}

\setkomafont{section}{\Large\rmfamily}

\usepackage{blindtext}

\begin{document}

\chapter{Hello World!}
\section{Section 1}
\blindmathpaper

\end{document}


There is just on detail missing:

## How can I place chapter and section numbers in the margin and align title and prefix with the text?

So basically I try to achieve:

• Your first call to \fontsize is not useful without a call to \selectfont... – Paul Gaborit Apr 16 '15 at 16:54
• @PaulGaborit but I get visual changes, when I change the fontsize? – thewaywewalk Apr 16 '15 at 17:11
• Here, you get visual change because the following \scshape implicitly calls \selectfont for you. If you comment \scshape, your call to \fontsize has no effect. It is better to explicitly call \selectfont just after \fontsize{...}{...}. – Paul Gaborit Apr 17 '15 at 6:30

Add the following definition for sections and alike

\renewcommand*\othersectionlevelsformat[3]{%
\llap{#3\autodot\enskip}%
}


and change the definition of \chapterformat to

\renewcommand*{\chapterformat}{%
{\fontsize{20}{30}\scshape\chapappifchapterprefix{}}%
\fontsize{120}{30}\selectfont\rlap{\thechapter\autodot}%
}


MWE:

\documentclass[
fontsize=12pt,
BCOR=15mm,
DIV=15,
twoside=true,
open=right,
chapterprefix = true,
]{scrbook}

\usepackage{fontspec}
\setmainfont[Numbers = OldStyle,Ligatures = TeX,SmallCapsFeatures = {Renderer=Basic}]{Minion Pro}

\usepackage{anyfontsize}
\setkomafont{chapter}{\normalfont\Huge}
\renewcommand*{\chapterformat}{%
{\fontsize{20}{30}\scshape\chapappifchapterprefix{}}%
\fontsize{120}{30}\selectfont\rlap{\thechapter\autodot}%
}
\renewcommand*{\raggedchapter}{\raggedleft}

\renewcommand*\othersectionlevelsformat[3]{%
\llap{#3\autodot\enskip}%
}

\setkomafont{section}{\Large\rmfamily}

\usepackage{blindtext}

\begin{document}

\chapter{Hello World!}
\section{Section 1}
\blindmathpaper

\end{document}


Output:

## UPDATE (KOMA-Script v3.17)

Starting with KOMA-Script v3.17, \othersectionlevelsformat doesn't work as before, so, instead of using

\renewcommand*\othersectionlevelsformat[3]{%
\llap{#3\autodot\enskip}%
}


you will have to use

\renewcommand*{\sectionformat}{%
\llap{\thesection\autodot\enskip}%
}


instead. If you also want that behavior for subsections, use

\renewcommand*{\subsectionformat}{%
\llap{\thesubsection\autodot\enskip}%
}


and so on.

• (+1) Nice answer. There is a problem though. The entries in \tableofcontents will have a huge white space in-between, how can we solve this, @karlkoeller ? – AboAmmar Jun 1 '15 at 4:20