I’m trying to adapt one of the answers to this question so that only the section text, and not the section number, has a coloured background. Unfortunately the use of \parbox seems to result in a non-uniform baseline (if you look closely, you can see that “This is the title” is rendered on a lower baseline than “0.1”):
What I’m after is something like the text underneath, but with the shading extending all the way to the right. The use of \parbox seems to be the problem (see here for example) but I don’t know how to make the shading work otherwise.
\documentclass[a4paper]{scrbook}
\usepackage{xcolor,lipsum}
\usepackage{titlesec}
\titleformat{name=\section}[block]
{\sffamily\large}
{}
{0pt}
{\colorsection}
\titlespacing*{\section}{0pt}{\baselineskip}{\baselineskip}
\newcommand{\colorsection}[1]{%
\thesection\ \colorbox{blue!20}{\parbox{\dimexpr\textwidth-2\fboxsep}{#1}}}
\begin{document}
\section{This is the title}
\noindent{\sffamily\large 0.1 \colorbox{blue!20}{This is the title}}
\end{document}



\usepackage{showframe}to see. – Sigur Jan 03 '20 at 18:26\parbox[t](otherwise test with a very long section title). But you still have to take care of box width. – Sigur Jan 03 '20 at 18:28