1

I am trying to setup a design for my sections and can't get around this problem: I wanna have a box around the section number (only the numbers) and right next to it the section title, which is easy enough to do, but I want it to also connect to a line, which is under the whole title. I was already able to set it up, but only for sections with one-line-titles. As soon as I have a section with more than one line the box and the line will be disconnected. The optimal solution would be for the box to automatically stretch down to wherever the line is, so it always connects.

Here's what I got so far: The way it works right now

But what I want should look like this: The way it should look like

Here is my MWE - I included booktabs and tikz, because I'm gonna use both anyway, so solutions including tikz or a tabular setup are perfectly fine.

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

Many thanks in advance.

1 Answer 1

0

I have found one solution myself using a table:

enter image description here

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

It serves my purpose, so I consider it a solution.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .