3

I have a customized KOMA-Script chapter heading, similar to cleanthesis. The chapter title and the chapter number should align on the bottom.

The problem occurs when the chapter title has two lines. The the second line is below the chapter number:

enter image description here enter image description here

Here is the MWE:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Preambel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[
    DIV=8,
    twoside=false,
]{scrbook}

\usepackage{microtype}
\usepackage{lmodern}
\usepackage{xcolor}
\usepackage{blindtext}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Layout chapter heading
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Space from top
\renewcommand*\chapterheadstartvskip{\vspace*{-4.1cm}}
\renewcommand*\chapterheadendvskip{\vspace*{2.5\baselineskip}}

\renewcommand*{\chapterformat}{\chapternumber{\thechapter}}
\renewcommand{\chapterlinesformat}[3]{\chaptertitle{#3}#2}

% Chapter rule and number
\newcommand{\chapternumber}[1]{%
    \usekomafont{chapter}%
    \begin{minipage}[t]{0.3\textwidth}%
        \raggedleft{%
            {\color{red}\rule[-5pt]{2pt}{7cm}}%
            \hspace{5mm}%
            {\color{red}\fontsize{60}{60}\selectfont#1}%
        }%
    \end{minipage}%
}

% Chapter title
\newcommand{\chaptertitle}[1]{%
    \usekomafont{chapter}%
    \begin{minipage}[t]{0.7\textwidth}%
        \vspace*{6.39cm}%
        #1%
    \end{minipage}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\chapter{Test chapter}
\section{Test section}
\Blindtext[2]

\chapter{Test chapter with very long title}
\section{Test section}
\Blindtext[2]

\end{document} 

If I change the argument of the minipages from t to b, I get the desired vertical alignment on the bottom. Unfortunately, the chapter number and the rule move down as well:

enter image description here enter image description here

I would like to anchor the position of both chapter number and rule and then stack the lines from the chapter title above each other, aligning on the bottom with the chapter number.

PS: Please ignore the horizontal jumping of the red line. This can be fixed with tabular figures.

2 Answers2

2

enter image description here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Preambel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[
    DIV=8,
    twoside=false,
]{scrbook}

\usepackage{microtype}
\usepackage{lmodern}
\usepackage{xcolor}
\usepackage{blindtext}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Layout chapter heading
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Space from top
\renewcommand*\chapterheadstartvskip{\vspace*{-4.1cm}}
\renewcommand*\chapterheadendvskip{\vspace*{2.5\baselineskip}}

\renewcommand*{\chapterformat}{\chapternumber{\thechapter}}
\renewcommand{\chapterlinesformat}[3]{\chaptertitle{#3}#2}

% Chapter rule and number
\newcommand{\chapternumber}[1]{%
    \usekomafont{chapter}%
    \begin{minipage}[b]{0.3\textwidth}%
        \vspace*{-6.39cm}%
        \raggedleft{%
            {\color{red}\rule[-5pt]{2pt}{7cm}}%
            \hspace{5mm}%
            {\color{red}\fontsize{60}{60}\selectfont#1}%
        }%
    \end{minipage}%
}

% Chapter title
\newcommand{\chaptertitle}[1]{%
    \usekomafont{chapter}%
    \vspace*{6.39cm}%
    \leavevmode\smash{\begin{minipage}[b]{0.7\textwidth}%
        #1%
    \end{minipage}}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\tableofcontents

\chapter*{A test chapter}
\Blindtext[1]

\chapter{Test chapter}
\section{Test section}
\Blindtext[2]

\chapter{Test chapter with very long title}
\section{Test section}
\Blindtext[2]

\end{document}
Schweinebacke
  • 26,336
David Carlisle
  • 757,742
  • Thank you, that worked! Could you explain to me the usage of \smash? In my case, it seemed to work without it. –  Jan 12 '17 at 10:46
  • Sorry to temporarily remove the acceptance. The code does work on the given example, but moves the title from starred chapters to the top due to the missing \vspace*{6.39cm}. –  Jan 12 '17 at 12:03
  • @jpmath oh you could add the space back:-) I just removed it as it was doing nothing as the text was aligned to the rule anyway, starred versions either don't want the \smash or want an "invisible" version of the rule, I'll look later – David Carlisle Jan 12 '17 at 12:14
  • @jpmath actualy the \smash probably isn't really needed in the version I finally posted, so you can probably just not use \smash and add the rule back, does that cover your use cases? – David Carlisle Jan 12 '17 at 12:16
  • I just managed to solve the problem: To fix the vertical position of starred chapters, add \vspace*{6.39cm}% in \chaptertitle before \leavevmode. To fix the hereby arising problem with the vertical position of the rule and the chapter number, add \vspace*{-6.39cm}% as new first line in the minipage of \chapternumber. Note that in this case I do need \smash. –  Jan 12 '17 at 12:32
  • @jpmath do you want to edit the above answer to what you actually used? – David Carlisle Jan 12 '17 at 12:37
1
\documentclass[
    DIV=8,
    twoside=false,
]{scrbook}

\usepackage{microtype}
\usepackage{lmodern}
\usepackage{xcolor}
\usepackage{blindtext}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Layout chapter heading
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\RedeclareSectionCommand[beforeskip=-2.5cm,afterskip=2.5\baselineskip]{chapter}

\renewcommand*{\chapterlinesformat}[3]{%
  \parbox[b][\ht\strutbox]{\linewidth}{%
    \parbox[b]{.7\linewidth}{#3}\hfill
    \parbox[b]{.3\linewidth}{%
      \hfill
      \color{red}\rule[-5pt]{2pt}{10cm}% the rule should be longer than visible
      \hspace{5mm}%
      \makebox[1em][r]{% remove this, if not numberes should habe the rule
                       % right aligned
        \fontsize{60}{60}\selectfont #2%
      }% and don't forget this ;-)
    }%
  }\par\nobreak
}
\renewcommand*{\chapterformat}{\thechapter}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\tableofcontents
\chapter{Test chapter}
\section{Test section}
\Blindtext[2]

\chapter{Test chapter with very long title}
\section{Test section}
\Blindtext[2]

\end{document}

Table of Contents (not numbered) and two chapters

Schweinebacke
  • 26,336