Set font size of chapter headings to 18 pt, section headings to 16 pt, subsection headings to 14 pt in KOMA script class srereprt

fontsizekoma-scriptsectioning

I want to change fontsize of chapter headings to 18 pt, section headings to 16 pt, subsection headings to 14 pt with 1.5 linespacing in the report as per our univeristy guidelines. I use luatex. I have tried googling and tried below method, but it sets chapter heading font size to normal size

\documentclass[12pt,abstract = true,toc = flat,toc = bib,enabledeprecatedfontcommands]{scrreprt}
\usepackage{lipsum}
\addtokomafont{disposition}{\rmfamily}
\setkomafont{chapter}{\fontsize{18}{27}}
\begin{document}
\chapter{The first}
This a test chap
\section{The section}
We will see how to write report in below subsection
\subsection{little brother of section}
Write report according to your university guidelines
\lipsum[1-2]
\end{document}

Best Answer

The short answer

The direction \setkomafont{chapter}{\fontsize{18}{27}} is not working because you are missing the command \selectfont (immediately) after the specifications. It is this command that actually updates the font attributes. You can read about font selection commands in this guide, §2.2. In the given example, amend the line to this:

\setkomafont{chapter}{\fontsize{18}{27}\selectfont}

Advice you didn't ask for: which parameters to use for \fontsize?

The second argument of \fontsize sets, of course, the value of \baselineskip that is to be used along with the specified font size.

Since you are going for a document with one-and-a-half line spacing, you chose 27pt for a font size of 18pt (18ptx1.5). Instead, I would recommend to keep the default ratio between \baselineskip and the font size. The ratio corresponding to normal spacing in the standard document classes is 1.2. Thus, you get 21.6pt for \chapter, 19.2pt for \section, 16.8pt for \subsection.

Why? Because you will need to set a line spacing (of one and a half) for the body of your document, not just for the chapter and section headings. If you issue a global command to do so, this will scale all elements in the document proportionally, including the headings.

To do this, use \linespread{<factor>}. Be aware, though, that this factor does not map one-to-one onto the desired line spacing, because it needs to be compounded by the value of \baselineskip. And since \baselineskip is 1.2, for one-and-a-half spacing you will need \linespread{1.25}; for double spacing, you'd need something like \linespread{1.6667}.

So, to achieve the values given in your guidelines, you can use the following code (the command \thefontsize shows the font size in points):

\documentclass[12pt]{scrreprt}

\usepackage{lipsum}

\makeatletter
\newcommand\thefontsize{(Font size = \f@size pt)}
\makeatother

\addtokomafont{disposition}{\rmfamily}

\setkomafont{chapter}{\fontsize{18}{21.6}\selectfont}
\setkomafont{section}{\fontsize{16}{19.2}\selectfont}   
\setkomafont{subsection}{\fontsize{14}{16.8}\selectfont}

\linespread{1.25}

\begin{document}
\chapter{Chapter \thefontsize}
\lipsum[1]
\section{Section \thefontsize}
\lipsum[1]
\subsection{Subsection \thefontsize}
\lipsum[1]
\end{document}

On the left is the document in the specified format, on the right the same document with \linespread commented out. Note how all line spacing, including around the headings, is scaled proportionally.

enter image description here