Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\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?

share|improve this question
    
Change \hfill into \raggedleft. You'll have to adjust the line breaks by hand with \\. –  egreg Feb 6 '12 at 11:45

1 Answer 1

up vote 6 down vote accepted

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

share|improve this answer
    
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. –  significant Feb 6 '12 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) –  significant Feb 6 '12 at 14:16
1  
delete the [t] after \parbox –  Herbert Feb 6 '12 at 14:21
    
thanks @Herbert! –  significant Feb 6 '12 at 16:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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