我有一个自定义的 KOMA-Script 章节标题,类似于cleanthesis
。章节标题和章节编号应在底部对齐。
当章节标题有两行时,就会出现问题。第二行位于章节号下方:
以下是 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}
minipages
如果我将from的参数更改t
为b
,我会在底部获得所需的垂直对齐。不幸的是,章节号和规则也会向下移动:
我想固定章节编号和规则的位置,然后将章节标题中的线条堆叠在一起,并与章节编号在底部对齐。
PS:请忽略红线的水平跳跃。这可以通过表格图形修复。
答案1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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}
答案2
\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}