具有多行的 KOMA 腳本部分編號框

具有多行的 KOMA 腳本部分編號框

我正在嘗試為我的部分設置設計,但無法解決這個問題:我想在部分編號(僅數字)周圍有一個框,並在其旁邊有一個部分標題,這很容易做到,但是我希望它也連接到整個標題下的一條線。我已經能夠設置它,但僅限於具有單行標題的部分。一旦我有一個包含多條線的部分,盒子和線就會斷開。最佳解決方案是盒子自動向下延伸到線路所在的位置,因此它始終連接。

這是我到目前為止得到的: 現在的運作方式

但我想要的應該是這樣的: 它應該是這樣的

這是我的 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

我自己使用表格找到了一個解決方案:

在此輸入影像描述

\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}

它符合我的目的,所以我認為這是一個解決方案。

相關內容