4

I am customizing section headings for scrartcl and wanted to try adding a rule after the section title filling the line.

As suggested in section 12.8. of the KOMA manual, instead of drawing the rule inside \AddtoDoHook directly, I am creating a command with an empty argument to avoid problems with the parameter introduced by \ExecuteDoHook. My attempt at doing this:

\documentclass{scrartcl}

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    
    \usepackage{xhfill}
    \usepackage{blindtext}

%% ----------------------------------------
%%  The issue:
    \newcommand{\hfilllinegobble}[1]{\xrfill[0.4ex]{1.5pt}}
    \AddtoDoHook{heading/endgroup/section}{\hfilllinegobble}


\begin{document}
    \blinddocument
\end{document}

When I try to run this, there is no output and I get the following error message, and I do not know what a 'glue' is or how to repair one.

Leaders not followed by proper glue. \blinddocument

However, I am using a similar method for adding a line below chapter headings in scrbook, which works perfectly fine:

\newcommand{\headinglinegobble}[1]{\vspace*{-1ex}\noindent\rule{\textwidth}{.5pt}} 

\AddtoDoHook{heading/endgroup/chapter}{\headinglinegobble}

How can I modify the section head without messing up the 'glue'? Are there better ways of customizing KOMA-headings in general?

1 Answer 1

5

There is a \@@par after the title and before \ExecuteDoHook{heading/endgroup/section} in the source code. Therefore you have to add a \leavevmode and the line will be below of the section title:

\AddtoDoHook{heading/endgroup/section}{\leavevmode\hfilllinegobble}

So I would suggest to redefine \sectionlinesformat, eg.:

\newcommand*{\hfilllinegobble}{\xrfill[0.4ex]{1.5pt}}
\newcommand*\originalsectionlinesformat{}
\let\originalsectionlinesformat\sectionlinesformat
\renewcommand\sectionlinesformat[4]{%
   \originalsectionlinesformat{#1}{#2}{#3}{#4\Ifstr{#1}{section}{ \hfilllinegobble}{}}%
}

Example:

\documentclass{scrartcl}
%\usepackage[utf8]{inputenc}% only needed with outdated TeX distributions
\usepackage[T1]{fontenc}
\usepackage{xhfill}
\usepackage{blindtext}% only for dummy text

%% ----------------------------------------
%%  The issue:
\newcommand*{\hfilllinegobble}{\xrfill[0.4ex]{1.5pt}}
\newcommand*\originalsectionlinesformat{}
\let\originalsectionlinesformat\sectionlinesformat
\renewcommand\sectionlinesformat[4]{%
   \originalsectionlinesformat{#1}{#2}{#3}{#4\Ifstr{#1}{section}{ \hfilllinegobble}{}}%
}

\begin{document}
\tableofcontents
\blinddocument
\end{document}

enter image description here

2
  • I still need to think about why and how this works, but it works perfectly, thanks!
    – schoekling
    Commented Feb 26, 2021 at 13:54
  • \sectionlinesformat etc. is explained in section 21.8. of the KOMA-Script manual.
    – esdd
    Commented Feb 26, 2021 at 17:35

You must log in to answer this question.

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