4
\def\thickhrule{\leavevmode \leaders \hrule height .5pt \hfill \kern \z@}
\def\position{\centering}
%% Note the difference between the commands the one is 
%% make and the other one is makes
\renewcommand{\@makechapterhead}[1]{%
  \vspace*{10\p@}%
  {\parindent \z@ \position \reset@font
       % {\Huge \scshape  \thechapter }
        \par\nobreak
        \vspace*{5\p@}%
        \interlinepenalty\@M
        \thickhrule
        \par\nobreak
        \vspace*{2\p@}%
            % hacken om nummer 0 niet te weergeven 
        \hfill {\Huge \bfseries \ifthenelse{\value{chapter}>0}{\thechapter{}}{} #1\par\nobreak}
        \par\nobreak
        \vspace*{2\p@}%
        \thickhrule
    \vskip 50\p@
  }}

%% This uses makes

\def\@makeschapterhead#1{%
  \vspace*{10\p@}%
  {\parindent \z@ \position \reset@font
        %{\Huge \scshape \vphantom{\thechapter}}
        \par\nobreak
        \vspace*{5\p@}%
        \interlinepenalty\@M
        \thickhrule
        \par\nobreak
        \vspace*{2\p@}%
        {\hspace*{0pt}\hfill \Huge \bfseries #1\par\nobreak}
        \par\nobreak
        \vspace*{2\p@}%
        \thickhrule
    \vskip 50\p@
  }}
\endinput

The above code defines a Sony style chapter heading, which looks nice in my point of view. For proper lay-out, I right align the chapter. However, for long chapter titles this yields a problem, the extra line gets centred.

How to fix this in the above code?

1
  • Change \hfill into \raggedleft. You'll have to adjust the line breaks by hand with \\.
    – egreg
    Feb 6, 2012 at 11:45

1 Answer 1

6

use a parbox with \raggedleft

\documentclass{book}
\makeatletter
\def\thickhrule{\leavevmode \leaders \hrule height .5pt \hfill \kern \z@}
\def\position{\centering}
%% Note the difference between the commands the one is 
%% make and the other one is makes
\renewcommand\@makechapterhead[1]{%
  \vspace*{10\p@}%
  {\parindent \z@ \position \reset@font
       % {\Huge \scshape  \thechapter }
        \par\nobreak
        \vspace*{5\p@}%
        \interlinepenalty\@M
        \thickhrule
        \par\nobreak
        \vspace*{2\p@}%
            % hacken om nummer 0 niet te weergeven 
        \noindent
        \parbox{\linewidth}{\raggedleft\Huge \bfseries 
          \ifnum\thechapter>0 \thechapter\space\fi #1}\par\nobreak}
        \par\nobreak
        \vspace*{2\p@}%
        \noindent
        \thickhrule
    \vskip 50\p@
  }

%% This uses makes

\def\@makeschapterhead#1{%
  \vspace*{10\p@}%
  {\parindent \z@ \position \reset@font
        %{\Huge \scshape \vphantom{\thechapter}}
        \par\nobreak
        \vspace*{5\p@}%
        \interlinepenalty\@M
        \thickhrule
        \par\nobreak
        \vspace*{2\p@}%
        \noindent
        \parbox{\linewidth}{\raggedleft\Huge \bfseries #1}
        \par\nobreak
        \vspace*{2\p@}%
        \thickhrule
    \vskip 50\p@
  }}
\makeatother

\begin{document}

\chapter{A very long title for my chapter}
foo

\chapter*{A very long title for my chapter}
foo
\end{document}

enter image description here

3
  • Herbert, that was the answer. However \ifnum\thechapter>0 \thechapter\space\fi Did not work. But problem solved, thanks! @egreg, thanks for modifying my post for correctly displaying the code. Feb 6, 2012 at 13:23
  • Small problem: If only one line is needed, the vertical alignment is false. The text is slighty placed above the center. How to fix this? (the current workstation is crappy, so I can not provide an pdf output example currently) Feb 6, 2012 at 14:16
  • 1
    delete the [t] after \parbox
    – user2478
    Feb 6, 2012 at 14:21

You must log in to answer this question.

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