9

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

4

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.

  • 2
    Seems to do the job but be careful if your chapter title is too long, it won't break the line... – Ludovic C. Sep 15 '13 at 16:33
  • @LudovicC.: Yes, and if that's a problem, a fix is possible. – Werner Sep 15 '13 at 16:34
2

Here's another approach using the interface offered by memoir to design a new chapter style; I also make some additional adjustments: the titles were always be placed inside a centered box which has a maximum width of 0.7\textwidth.

This approach allows to define the behaviour for both numbered and unnumbered chapters, without redefining internal commands:

\documentclass{memoir}
\usepackage{lipsum}
\usepackage{varwidth}

\makeatletter
\makechapterstyle{mystyle}{%
  \chapterstyle{default}
  \renewcommand*{\chapnamefont}{\normalfont\scshape}
  \renewcommand*{\chapnumfont}{\normalfont\scshape}
  \renewcommand*{\printchaptername}{%
    \chapnamefont\centering\@chapapp}
  \renewcommand*{\printchapternum}{\chapnumfont\thechapter}
  \renewcommand*{\chaptitlefont}{\normalfont\Huge\itshape}
  \renewcommand*{\printchaptertitle}[1]{%
\makebox[\linewidth][c]{\makebox[\dimexpr\textwidth+4em\relax][c]{%
    \hrulefill\hspace{1em}\raisebox{-.65ex}{\begin{varwidth}{\dimexpr0.7\textwidth-2em\relax}\centering\chaptitlefont##1\end{varwidth}}\hspace*{1em}\hrulefill}}}
  \renewcommand*{\afterchaptertitle}{\vskip\afterchapskip}
  \renewcommand*{\printchapternonum}{%
    \vphantom{\chapnumfont \textit{9}}\afterchapternum}
}
\makeatother

\chapterstyle{mystyle}

\begin{document}

\chapter{Implementation}
\lipsum[4]
\chapter{A long title spanning more than one line}
\lipsum[4]
\chapter*{A title for an unnumbered chapter}
\lipsum[4]

\end{document}

An image for a numbered chapter with a short title:

enter image description here

An image for a numbered chapter with a longer title:

enter image description here

An image for an unnumbered chapter:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.