# correct way of design KOMA-Script heading styles

I'm new in adjusting LaTeX code for chapter headings. I tried to search on the forum for some information on KOMA-Script chapter heading, which I found some. However, I'm not succeeding in what I want from it.

Can somebody explain a little on my MWE, and the generel/minimal input to adjust titles for the KOMA-Script.

Regarding what I want for the document, how to

• Align the chapter number on the right side of the left margin par

• Align the chapter name on the left side of the body

• Control the vertical space between the top of the body and the chapter number and name

\documentclass{scrreprt}

\usepackage[
includemp,
showframe,
reversemp,
paperwidth=20.1cm,
paperheight=25.80cm,
top=2.30cm,
bottom=3.4cm,
inner=2.7cm,
outer=2.7cm,
marginparwidth=1.6cm, % Fixed for now
marginparsep=0.4cm
]{geometry}

\makeatletter          % to set the marginpar on the left side in showframe
\let\Gm@vrules@mpi\Gm@vrules@mpii
\makeatother

\newlength\mylen
\setlength\mylen{\dimexpr\oddsidemargin+\hoffset\relax}

\renewcommand*{\chapterformat}{%
{\normalfont\Large\bfseries}
{\llap{\hspace*{-\mylen}\thechapter\hfill}}{}
}

\renewcommand*{\sectionformat}{%
{\normalfont\Large\bfseries}
{\llap{\hspace*{-\mylen}\thesection\hfill}}{}
}

\renewcommand*{\subsectionformat}{%
{\normalfont\Large\bfseries}
{\llap{\hspace*{-\mylen}\thesubsection\hfill}}{}
}

\begin{document}

\chapter{test}
\section{test}
\subsection{test}

\end{document}


Corresponding »Beispiel für Gliederungenummern in den Rand ausrücken« (Link to German page) you can put the headings numbers right aligned into the left margin, using:

\renewcommand*{\chapterformat}{\makebox[0pt][r]{\chapappifchapterprefix{\ }\thechapter\autodot\hskip\marginparsep}}%
\renewcommand*{\sectionformat}{\makebox[0pt][r]{\thesection\autodot\hskip\marginparsep}}
\renewcommand*{\subsectionformat}{\makebox[0pt][r]{\thesubsection\autodot\hskip\marginparsep}}
\renewcommand*{\subsubsectionformat}{\makebox[0pt][r]{\thesubsubsection\autodot\hskip\marginparsep}}


The \…format commands are used to output the headings numbers. \makebox[0pt][r] is used to do the output left beside the start of the headings. \hskip\marginparsep is used to have the normal distance between the margin column and the text area.

The distance between the beginning of the text area and the chapter headings can be controlled using option beforeskip of command \RedeclareSectionCommand, e.g.,

\RedeclareSectionCommand[beforeskip=0pt,afterindent=false]{chapter}


Because the default afterindent=bysign means, that values of beforeskip greater or equal to zero result in indent of the first paragraph after the chapter title, afterindent=false is used to explicitly prevent the indent.

KOMA-Script versions before 3.26 do not provide option afterindent. So with old KOMA-Script versions you have to use something like:

\RedeclareSectionCommand[beforeskip=-1sp plus -1sp minus 1sp]{chapter}% remove the vertical skip before the chapter heading


which is almost the same but less intuitive.

For more information about \RedeclareSectionCommand and all its options (e.g., belowskip to control the distance below the heading) see part II of the English KOMA-Script manual or the German KOMA-Script manual or even the German KOMA-Script book.

As a MWE:

\documentclass{scrreprt}

\usepackage[
includemp,
showframe,
reversemp,
paperwidth=20.1cm,
paperheight=25.80cm,
top=2.30cm,
bottom=3.4cm,
inner=2.7cm,
outer=2.7cm,
marginparwidth=1.6cm, % Fixed for now
marginparsep=0.4cm
]{geometry}

\makeatletter          % to set the marginpar on the left side in showframe
\let\Gm@vrules@mpi\Gm@vrules@mpii
\makeatother

\renewcommand*{\chapterformat}{\makebox[0pt][r]{\chapappifchapterprefix{\ }\thechapter\autodot\hskip\marginparsep}}%
\renewcommand*{\sectionformat}{\makebox[0pt][r]{\thesection\autodot\hskip\marginparsep}}
\renewcommand*{\subsectionformat}{\makebox[0pt][r]{\thesubsection\autodot\hskip\marginparsep}}
\renewcommand*{\subsubsectionformat}{\makebox[0pt][r]{\thesubsubsection\autodot\hskip\marginparsep}}

\RedeclareSectionCommand[beforeskip=0pt,afterindent=false]{chapter}% remove the vertical skip before the chapter heading without activation of first paragraph indent
% With KOMA-Script before version 3.26 you have to use instead of the line above:
% \RedeclareSectionCommand[beforeskip=-1sp plus -1sp minus 1sp]{chapter}% remove the vertical skip before the chapter heading

\usepackage{mwe}

\begin{document}

\chapter{test}
\section{test}
\subsection{test}
\lipsum

\end{document}