自定义章节中有两行填充

自定义章节中有两行填充
\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

上面的代码定义了一个 Sony 风格的章节标题,在我看来,这看起来不错。为了获得正确的布局,我将章节右对齐。但是,对于较长的章节标题,这会产生一个问题,多余的行会居中。

如何在上面的代码中修复这个问题?

答案1

使用 parbox\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}

在此处输入图片描述

相关内容