我对 Latex 不太了解,经过长时间无果的修补后,我想在这里问一个问题。
我正在使用 scrbook KOMA 脚本编写大型文档。对于章节标题格式,我使用如下样式 ([https://texblog.org/2012/07/03/fancy-latex-chapter-styles/][1]):
对于单行标题,这看起来不错。但是,对于多行章节标题,我想更改样式,使灰色条延伸到所有行,并且章节号垂直对齐在灰色条的中间。
梅威瑟:
\documentclass[a4paper,fontsize=12pt,oneside]{scrbook}
\usepackage{xcolor}
\renewcommand*{\chapterformat}{%
\thechapter \enskip
\textcolor{gray!50}{\rule[-\dp\strutbox]{2pt}{\baselineskip}}\enskip
}
\begin{document}
\chapter{Single-line Chapter}
\chapter{Multi-line Chapter Multi-line Chapter Multi-line Chapter Multi-line Chapter }
\end{document}
如果有人能帮助我就太好了。提前谢谢!
谨致问候,
汤姆
答案1
您可以重新定义\chapterlinesformat
,例如。
\documentclass[a4paper,fontsize=12pt,oneside]{scrbook}
\addtokomafont{chapter}{\rmfamily\mdseries\scshape}
\usepackage{xcolor}
\renewcommand*{\chapterformat}{\thechapter}
\newsavebox\chapternumberbox
\newsavebox\chaptertextbox
\let\originalchapterlinesformat\chapterlinesformat
\renewcommand\chapterlinesformat[3]{%
\IfArgIsEmpty{#2}
{\originalchapterlinesformat{#1}{#2}{#3}}
{\ifstr{#1}{chapter}
{%
\savebox\chapternumberbox{#2}%
\savebox\chaptertextbox{%
\parbox{\dimexpr\textwidth-\wd\chapternumberbox-1em-2pt\relax}{\raggedright#3}%
}%
\raisebox{\dimexpr-.25\dp\strutbox}
{\usebox\chapternumberbox}%
\enskip
\textcolor{gray!50}{%
\rule[\dimexpr-\dp\chaptertextbox-.5ex\relax]{2pt}
{\dimexpr\ht\chaptertextbox+\dp\chaptertextbox+1ex\relax}%
}%
\enskip
\usebox\chaptertextbox
\par
}
{\originalchapterlinesformat{#1}{#2}{#3}}%
}%
}
\begin{document}
\tableofcontents
\chapter{Single-line Chapter}
\chapter{Multi-line Chapter Multi-line Chapter Multi-line Chapter Multi-line Chapter }
\end{document}