KOMA-章节标题上方和下方的脚本行

KOMA-章节标题上方和下方的脚本行

我使用 KOMA-Script,我想在章节标题上方和下方添加一行。因此,上行应该位于“章节”和标题之间。我用

\documentclass{scrbook}
\KOMAoptions{headings=chapterprefix}

\usepackage{etoolbox}
\usepackage{blindtext}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Adding lines above and below the chapter head
%
%%%%%%%% BEFORE HEADING
% \appto\chapterheadstartvskip{%
%   {%
%       \noindent\rule{\linewidth}{1pt}\par%
%   }%
% }   
%%%%%%%% AFTER HEADING
\preto\chapterheadendvskip{%
    {%  
        \noindent\rule{\linewidth}{1pt}\par%
    }%
}
%%%%%%%% BETWEEN LABEL AND HEADING
\renewcommand*{\chapterheadmidvskip}{%
    {%
        \vspace{-.3\baselineskip}%
        \par\noindent%
        \noindent\rule{\linewidth}{1pt}
    }%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\chapter{Test}
\blindtext

\chapter*{Test the second}
\blindtext
\end{document}

问题出在\chapter*。它没有上面的行。如果我在现在注释的示例中包括代码的第一部分,我会得到上面的行\chapter*,但也会得到上面的第三行\chapter

\chapterheadstartvskip有没有办法分别定义chapterchapter*?或者有什么类似的东西\isThisAChapterWithAsteriks

答案1

使用 KOMA-Script 版本 3.19a(当前在 CTAN 和 TL2015 和 MiKTeX2.9 中)或更新版本,您可以重新定义\chapterlineswithprefixformat以插入行(如果headings=chapterprefix设置了选项):

\documentclass[
  headings=chapterprefix
]{scrbook}
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif

\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}}

\RedeclareSectionCommand[innerskip=0pt]{chapter}

\renewcommand\chapterlineswithprefixformat[3]{%
  #2\nobreak%
  \Ifstr{#2}{}{}{\kern-\dp\strutbox}%
  \titlerule\par\nobreak%
  #3%
  \par\nobreak\titlerule%
}

\usepackage{blindtext}

\begin{document}
\chapter{Test}
\blindtext

\chapter*{Test the second}
\blindtext
\end{document}

在此处输入图片描述

在此处输入图片描述


如果没有的话这些线也应该存在,那么headings=chapterprefix您也必须重新定义\chapterlinesformat

\makeatletter
\renewcommand\chapterlinesformat[3]{%
  \titlerule\par\nobreak%
  \@hangfrom{#2}{#3}%
  \par\nobreak\titlerule%
}
\makeatother

相关内容