KOMA スクリプト セクション 複数行の番号ボックス

KOMA スクリプト セクション 複数行の番号ボックス

セクションのデザインを設定しようとしていますが、この問題を回避できません。セクション番号 (数字のみ) の周りにボックスを配置し、そのすぐ隣にセクション タイトルを配置したいのですが、これは簡単に実行できますが、タイトル全体の下にある線にも接続する必要があります。すでに設定できていましたが、1 行のタイトルのセクションのみでした。セクションに複数の行があると、ボックスと線が切断されます。最適な解決策は、ボックスが線がある場所まで自動的に伸びて、常に接続されるようにすることです。

これまでに得たものは次のとおりです。 現状の仕組み

しかし、私が望むのは次のようになります。 こうあるべき

これが私の MWE です - booktabs と tikz を含めました。どちらもいずれ使用する予定なので、tikz または表形式のセットアップを含むソリューションでまったく問題ありません。

\documentclass[parskip=half]{scrreprt}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{lipsum}

\makeatletter
  \renewcommand\sectionlinesformat[4]{\Ifstr{#1}{section}
     {\rlap{}\colorbox{darkgray}{\raisebox{0pt}[13pt][3pt]{
     \makebox{\selectfont\color{white}{\thesection}}}}\enskip#4\par\nobreak
     \kern-1.48\ht\strutbox\textcolor{darkgray}{\rule{\linewidth}{.8pt}}}
     {\@hangfrom{\hspace*{#2}#3}{#4}}
}
\makeatother

\begin{document}

\chapter{Some random chapter}
Don't even care for the chapter!

\section{Some short titled section}
\lipsum[1]

\section{Some very long titled section title, which is way too long to fit in one line, so it takes up more lines and destroys my section style}
\lipsum[1]

\end{document}

よろしくお願いします。

答え1

私はテーブルを使用して 1 つの解決策を見つけました:

ここに画像の説明を入力してください

\documentclass[parskip=half]{scrreprt}      
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{lipsum}
\usepackage[table,xcdraw]{xcolor}

\newcommand\btrule[1]{\specialrule{#1}{0pt}{0pt}}

\renewcommand\sectionlinesformat[4]{
\arrayrulecolor{darkgray}\begin{tabularx}{\textwidth}{>{\columncolor{darkgray}}>{\raggedright}l@{}p{0.01cm}Xc}
\textcolor{white}{\thesection} & & #4 \\ \btrule{1.5pt}
\end{tabularx}
}

\begin{document}

\chapter{Some random chapter}
Don't even care for the chapter!

\section{Some short titled section}
\lipsum[1]

\section{Some very long titled section title, which is way too long to fit in one line, so it takes up more lines and destroys my section style}
\lipsum[1]

\end{document}

それは私の目的を果たしているので、解決策だと考えています。

関連情報