I know I need to use the x from the counter
node and the y from the rectangle
node, but so far the right syntax has eluded me.
Green indicates what I'm trying to fill, and red indicates the where the line should extend to.
\documentclass{scrbook}
\usepackage[letterpaper,asymmetric,left=108pt,right=54pt,top=41pt,bottom=41pt,headsep=13pt,headheight=14pt,footskip=23pt,marginparwidth=72pt]{geometry}
\usepackage[compact,explicit,calcwidth]{titlesec}
\usepackage{tikz,lipsum}
\usetikzlibrary{calc}
\setkomafont{section}{\normalfont\bfseries}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\newlength\titlemarginwidth
\setlength\titlemarginwidth{54pt}
\newcommand\boxedsection[1]{{%
\usekomafont{sectioning}\usekomafont{section}%
\begin{tikzpicture}[x=1pt,y=1pt,inner sep=0, inner ysep=0.7ex]
\node[anchor=base west,text width=\titlemarginwidth-\columnsep,color=white] at (0,0) (counter) {\hspace{1ex}\thesection};
\node[anchor=base west,text width=\textwidth] at ($(counter.base east)+(\columnsep,0)$) (rectangle) {#1};
\begin{pgfonlayer}{background}
\fill[color=black] let \p1=(counter.north), \p2=(counter.north) in (0,{max(\y1,\y2)}) rectangle (counter.south east);
\draw[black,thick] let \p1=(counter.north), \p2=(counter.north) in (0,{max(\y1,\y2)}) -- (rectangle.north east);
\draw[black,thick] (rectangle.south west) -- (rectangle.south east);
\end{pgfonlayer}
\end{tikzpicture}
}}
\titlespacing{\section}{-\titlemarginwidth}{1em}{0em}
\titleformat{\section}[block]
{}%
{}{0pt}{\boxedsection{#1}}
\begin{document}
\chapter{Testing One Two Three!}
\section{Extremely long section title that is absolutely absurd and obnoxious that goes on forever and ever and ever and ever!}
\lipsum[1]
\end{document}
I switched to tikz
after having trouble with spacing using just titlesec
rules and boxes.
This answer was extremely helpful in getting me started.
(counter|-rectangle)