[Tex/LaTex] Overfull hbox in rule below chapter title

boxeschapterskoma-scriptrulessectioning

I am writing a report with the KOMA-Script class scrreprt. Below each chapter title, I am creating a rule which goes all the way to the end of the paper:

Example image

This actually works fine, but creates an overfull hbox warning at every chapter title:

Overfull \hbox (89.62619pt too wide) in paragraph

I am not very surprised by this warning, as I am creating a too wide box. The 89.62619pt is exactly the length between the right end of the paragraph and the end of the paper.

Is there a way to create such rules without creating overfull boxes? Or otherwise, is there a way to suppress this warning (but only for this rule in the chapter heading)?

Here is a MWE containing my redefinition of the chapter heading and a test case:

\documentclass{scrreprt}
\usepackage{calc}

\makeatletter
\renewcommand{\@makechapterhead}[1]{
    \hfill
    \begin{minipage}[b]{9cm}
        \raggedleft
        \sffamily\huge\textbf{#1}
    \end{minipage}
    \quad
    \sffamily\huge\textbf{\thechapter}
    \vskip 5\p@
    \noindent
    \rule{\paperwidth-\oddsidemargin-\hoffset-1in}{0.7pt}
    \vskip 20\p@
    \normalfont\normalsize
}
\makeatother

\begin{document}
    \chapter{A test chapter}
    Some example text.

    \chapter{Another very long chapter title which will break}
    Even more text.

\end{document}

Small comment: I am creating the minipage so chapter titles which are longer than one line also work correctly. If there is a better way of doing this, I am happy about suggestions.

Best Answer

Here is only an additional suggestion how the chapter title could be formatted: With the new KOMA-Script Version 3.19 you can redefine \chapterlinesformat to change the layout of the chapter heading. This works also for unnumbered chapters like the table of contents.

\documentclass{scrreprt}[2015/09/29]

\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=20pt,
  font=\huge
]{chapter}

\renewcommand\raggedchapter{\raggedleft}
\renewcommand\chapterformat{\thechapter}

\renewcommand\chapterlinesformat[3]{%
  \parbox[b]{\textwidth}{%
    \raggedchapter%
    \begin{minipage}[b]{9cm}
        \raggedchapter #3
    \end{minipage}%
    \ifstr{#2}{}{}{\quad#2}\\*
    \makebox[\textwidth][l]{\rule{\paperwidth}{.7pt}}%
  }%
}

\begin{document}
    \tableofcontents
    \chapter{A test chapter}
    Some example text.
    \chapter{Another very long chapter title which will break}
    Even more text.
\end{document}

Note that version 3.19 is already on CTAN and will be soon in TeXLive and MiKTeX. But you can also install the current version from the repository on the KOMA-Script Website.

enter image description here

enter image description here