将 titlesec-chapter 样式替换为 KOMA

将 titlesec-chapter 样式替换为 KOMA

我用 titlesec 构建了一个非常漂亮的章节样式:

在此处输入图片描述 不幸的是,与“scrbook”一起使用时会出现警告。这就是为什么我想用 KOMA 替换 titlesec。

谁能帮助我或者提示我如何替换此代码?

   \usepackage{titlesec}
%CHAPTER
\titleformat{\chapter}[display] %shape
        {\usefont{T1}{lmss}{b}{n}\filleft\huge\bfseries}    %format
        {\makebox[\linewidth][r]{\raisebox{103pt}[0pt][0pt]{\textcolor{gray!25}{\usefont{T1}{lmss}{b}{n}\fontsize{80pt}{95pt}\selectfont\thechapter}}}
        {}  %default would be huge
        }   %label
        {-14ex} %sep
        {}  %before-code
        [\vspace{0.5ex}\titlerule]


\titleformat{name=\chapter,numberless}[display]
{\usefont{T1}{lmss}{b}{n}\filleft\huge\bfseries}    %format
        %{\makebox[25pt][l]{\raisebox{100pt}[0pt][0pt]{\textcolor{gray!25}{\usefont{T1}{lmss}{b}{n}\fontsize{80pt}{80pt}\selectfont\thechapter}}}
        {\makebox[10pt][l]{\raisebox{10pt}[0pt][0pt]{\textcolor{gray!25}{\usefont{T1}{lmss}{b}{n}\fontsize{10pt}{12pt}\selectfont}}}
        {}  %default would be huge
        }   %label
        {-16.8ex}   %sep
        {}  %before-code
        [\vspace{1ex}\titlerule]

\titlespacing{\chapter}
             {0pc}{*30}{*5}[0pc] %Abstand zum linken Rand |Abstand zum oberen Text | Abstand zum unteren Text | Abstand zum rechten Rand 

%SECTION
\titleformat{\section}
        {\usefont{T1}{lmss}{b}{n}\filright\Large}
        {\thesection}{1em}{}

\titlespacing{\section}
             {0pc}{*0}{*-1}[0pc]

\setcounter{secnumdepth}{3}

%SUBSECTION 
\titleformat{\subsection}
        {\usefont{T1}{lmss}{b}{n}\large}
        {\thesubsection}{1em}{}

    \titlespacing{\subsection}
             {0pc}{*0}{*-1}[0pc]

我还希望附录看起来与普通章节一样。

其他没有编号的章节应如下所示:

无章号的章节标题上方的高度与有章号的章节编号上方的高度应该相同。

有很多问题... -.- 我希望有人能帮助我解决这个问题,因为我的 KOMA 知识很差 -.-

谢谢!

经过一番研究,我最终

在此处输入图片描述

  \renewcommand*\raggedchapter{\raggedleft}
  \addtokomafont{chapter}{\raggedleft\usefont{T1}{lmss}{b}{n}\huge\bfseries}

\newcommand\titlerule[1][.4pt]{\rule[.5\baselineskip]{\textwidth}{#1}}
\renewcommand*{\chapterformat}{%
\makebox[\width][l]{\scalebox{1}{{\nobreakspace}}%
\scalebox{4}{\textcolor{gray!25}\thechapter\autodot}\enskip}
}
\renewcommand*\chapterheadendvskip{\noindent\rule{\linewidth}{0.5pt}\par\vspace{\baselineskip}}

它似乎有效,但不幸的是缺少了一些东西:

  • 章节编号未完全显示在右侧
  • 我如何更改号码、姓名和线路之间的空格?
  • 无章号的章节标题上方的高度与有章号的章节编号上方的高度不一样。

答案1

这是重新定义的建议\chapterlineswithprefixformat。这需要 KOMA-Script 版本 3.19a 或更新版本。

\documentclass[chapterprefix]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{lmodern}

\RedeclareSectionCommand[
  beforeskip=\dimexpr3.3\baselineskip+1\parskip\relax,
  innerskip=0pt,% <- space between chapter number and chapter title
  afterskip=1.725\baselineskip plus .115\baselineskip minus .192\baselineskip
]{chapter}
\renewcommand\raggedchapter{\raggedleft}
\renewcommand\chapterformat{{\fontsize{80pt}{80pt}\selectfont\textcolor{gray!25}{\thechapter}}}
\renewcommand\chapterlineswithprefixformat[3]{%
  #2#3%
  \vspace*{-.5\baselineskip}% <- adjust the space between the chapter and the rule here
  \rule{\textwidth}{.4pt}\par\nobreak
}%

\RedeclareSectionCommands[
  beforeskip=0pt plus 1ex minus .2ex,
  afterskip=1sp plus .2ex
]{section,subsection}
\renewcommand*{\sectionformat}{\thesection\hspace*{1em}}
\renewcommand*{\subsectionformat}{\thesubsection\hspace*{1em}}

\setcounter{secnumdepth}{3}

\usepackage{blindtext}% for dummy text
\begin{document}
\tableofcontents
\blinddocument
\chapter{A long long long long long long long long long chapter title}
\Blindtext
\appendix
\blinddocument
\end{document}

根据您的需要调整beforeskipinnerskipafterskip分段命令。

在此处输入图片描述


关于评论:

如果页面顶部和章节编号或未编号章节之间应有相同的垂直空白,请使用与beforeskip章节相同的固定长度

\RedeclareSectionCommand[
  beforeskip=3.3\baselineskip,
  ...
]{chapter}

并在编号章节前插入一些额外的垂直空间

\renewcommand\chapterlineswithprefixformat[3]{%
  \ifstr{#2}{}{}{\vspace*{1ex}}% <- insert vertical space before numbered chapters
  #2#3%
  \vspace*{-.5\baselineskip}% <- adjust the space between the chapter and the rule here
  \rule{\textwidth}{.4pt}\par\nobreak
}%

或者删除未编号章节前的一些垂直空间

\renewcommand\raggedchapter{\raggedleft}
\renewcommand\chapterformat{{\fontsize{80pt}{80pt}\selectfont\textcolor{gray!25}{\thechapter}}}
\renewcommand\chapterlineswithprefixformat[3]{%
  \ifstr{#2}{}{\vspace*{-1ex}}{}% <- remove vertical space before unnumbered chapters
  #2#3%
  \vspace*{-.5\baselineskip}% <- adjust the space between the chapter and the rule here
  \rule{\textwidth}{.4pt}\par\nobreak
}%

相关内容