[Tex/LaTex] Place chapter title between two lines

chaptersrulestitles

I want to place a chapter title between two lines. The lines shall be on the left and the right side of the centered title like in this screenshot:

Desired result

Note that the lines are slightly overhanging the text below. It would be nice if I could do the same. Obviously the length of the chapter titles is varies, so the solution needs to automatically adapt to the length.

By now I have the following:

\documentclass{memoir}
\usepackage{graphics}
\usepackage{fontspec}

\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1pt \hfill \kern \z@}
\def\@makechapterhead#1{%
  \vspace*{60\p@}%
  {\parindent \z@ \centering \reset@font
          {\color{headings}
            \scshape \large \@chapapp{} \thechapter
          }
        \par\nobreak
        \interlinepenalty\@M
    \Huge \itshape #1\par\nobreak
    \thickhrulefill
    \par\nobreak
    \vskip 40\p@
  }}
\usepackage{lipsum}
\setcounter{chapter}{12}
\begin{document}

\chapter{Implementation}
\lipsum
\end{document}

which gives me this:

Current state

Best Answer

Here is an idea:

enter image description here

\documentclass{memoir}% http://ctan.org/pkg/memoir

\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1pt \hfill \kern \z@}
\def\@makechapterhead#1{%
  \vspace*{60\p@}%
  {\parindent \z@ \centering \reset@font
          {
            \scshape \large \@chapapp{} \thechapter
          }
        \par\bigskip\nobreak
        \interlinepenalty\@M
    \makebox[\linewidth]{%
      \makebox[\dimexpr\linewidth+4em]{\Huge \itshape \thickhrulefill~\raisebox{-.5ex}{#1}~\thickhrulefill}}\par\nobreak
    \par\nobreak
    \vskip 40\p@
  }}
\usepackage{lipsum}
\setcounter{chapter}{12}
\begin{document}

\chapter{Implementation}
\lipsum
\end{document}

I've placed the header (only the chapter title) inside a box of with \linewidth, which ensure no overfull \hboxes. Then, inside that box, I place two \thickhrulefills beside the actual title, inside another box of width \linewidth+4em. Since these boxes centre their content by default, it allows for a 2em overhang on either side.

A slight raise of -1ex (or a drop) centres the heading with respect to the rules.

Related Question