11

This question is more or less a duplicate of this similarly named question, but is not exactly the same. I also want to place a horizontal rule below each section title (exactly like in the linked question). The answer to this existing question only shows how to achieve this using the titlesec package.

However I am using the KOMA-Script class scrreprt, and it is not recommended to use titlesec and KOMA-Script together, as titlesec breaks several KOMA-Script features and KOMA-Script complains about that in a warning.

It appears that \DeclareSectionCommand can only change the vertical skip before / after the section title. Finally there exist commands like \At@startsection to add something before the section title, but nothing to add anything after the section title.

Is there any way to make KOMA-Script print a rule after the section title without using the titlesec package?

A small MWE:

\documentclass{scrreprt}
\begin{document}
    \chapter{The first chapter}
    \section{A nice section}
    Some text
\end{document}

Desired result (rule doesn't have to be red):

result

2
  • What about multiline titles?
    – egreg
    Sep 16, 2015 at 13:06
  • I don't plan on using multiline titles, but of course it would be nicer if that worked like single-line titles.
    – hbaderts
    Sep 16, 2015 at 15:46

2 Answers 2

14

This will be possible with KOMA-Script version 3.19 or newer. There is a newcommand \sectionlinesformat that can be redefined to insert the line after a section title.

\documentclass{scrreprt}[2015/09/15]% needs Version 3.19 or newer

\makeatletter
\renewcommand{\sectionlinesformat}[4]{%
\ifstr{#1}{section}{%
    \parbox[t]{\linewidth}{%
      \raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
      \kern-.75\ht\strutbox\rule{\linewidth}{.8pt}%
    }%
  }{%
    \@hangfrom{\hskip #2#3}{#4}}% 
}
\makeatother

\usepackage{blindtext}% only dummy text
\begin{document}
    \chapter{The first chapter}
    \section{A nice section}
    \Blindtext[2]
    \addsec{A nice section without number}
    \blindtext
\end{document}

Result:

enter image description here

1
  • Great, this was exactly what I was looking for. After manually updating to the newest KOMA-Script version, this works nicely.
    – hbaderts
    Sep 16, 2015 at 15:52
5

Maybe this might be a start.

\documentclass{scrreprt}
\let\svsection\section
\def\section#1{\svsection{#1}\noindent\smash{\rule[3ex]{\textwidth}{2pt}}\par%
  \vspace{-\baselineskip}\noindent}
\begin{document}
    \chapter{The first chapter}
    \section{A nice section}
    Some text
\end{document}

enter image description here

1
  • Nice, thank you for your help. This solution comes with the advantage that it also works for standard-classes (report ...)
    – hbaderts
    Sep 16, 2015 at 15:54

You must log in to answer this question.

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