I want to format my (sub)section numbering in a colored box and a horizontal line below the title. I need something like this:
I tried sectsty but could not get the line to work.
\documentclass{scrbook}
\usepackage{sectsty}
\usepackage[table]{xcolor}
\usepackage{blindtext}
\colorlet{sectitlecolor}{darkgray}
\colorlet{sectboxcolor}{darkgray}
\colorlet{secnumcolor}{white}
\sectionfont{\color{sectitlecolor}}
\makeatletter
\renewcommand@seccntformat[1]{%
\colorbox{sectboxcolor}{\textcolor{secnumcolor}{\csname the#1\endcsname}
}%
\quad
}
\makeatother
\begin{document}
\section{Section 1}
\blindtext
\subsection{Subsection 1}
\blindtext
\end{document}
Thanks in advance!!


