我正在使用这个https://github.com/derric/cleanthesis模板,但是它结合了 titlesec 和 KOMA 脚本,我想避免这种情况。
以下是章节样式的一个示例:
\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}
\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}
\newcommand\mychapformat[1]{%
\parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#1}}
\titleformat{\chapter}[display]%
{\usekomafont{chapter}\sectfont}%
{\vspace{-8em}\raggedleft{%
{\color{ctcolorchapterline}%
\rule[-5pt]{2pt}{5cm}}\quad%
{\color{ctcolorchapternum}
\fontsize{60}{60}\selectfont\thechapter}%
}%
}%
{-2.1em}%
{\mychapformat}%
[\phantomsection]
\begin{document}
\chapter{A test chapter with a long title that will span two lines}
\lipsum[4]
\end{document}
有没有办法可以仅使用 KOMA 脚本重现彩色线和章节编号以及章节名称换行符?
答案1
也许以下内容有帮助:
\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}
\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}
\RedeclareSectionCommand[
beforeskip=-1sp
]{chapter}
\makeatletter
\renewcommand\chapterlinesformat[3]{%
\ifstr{#1}{chapter}
{%
\parbox[b][\ht\strutbox]{\textwidth}{%
\parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#3}%
\makebox[3em][r]{%
\hfill
#2%
}%
}%
}{\@hangfrom{#2}{#3}}% <- original definition for other levels
}
\makeatother
\renewcommand\chapterformat{%
\textcolor{ctcolorchapterline}{\rule[-5pt]{2pt}{5cm}}%
\quad
{\fontsize{60}{60}\selectfont\textcolor{ctcolorchapternum}{\thechapter}}%
}
\begin{document}
\tableofcontents
\chapter{A test chapter with a long title that will span two lines}
\lipsum[4]
\chapter{Chapter with short title}
\lipsum
\end{document}
请注意,此建议仅限于一位数(例如您的 MWE)。
使用情况更新appendixprefix=true
正如您在下面的评论中提到的,您想要设置appendixprefix=true
。因此,我假设您想使用附录中章节标题的默认布局。然后您必须将的重新定义更改\chapterformat
为
\renewcommand\chapterformat{%
\IfUsePrefixLine{%
\mbox{\chapappifchapterprefix{\nobreakspace}\thechapter\autodot\enskip}%
}{%
\textcolor{ctcolorchapterline}{\rule[-5pt]{2pt}{5cm}}%
\quad
{\fontsize{60}{60}\selectfont\textcolor{ctcolorchapternum}{\thechapter}}%
}%
}