在 Scrbook 中划下章节标题和编号

在 Scrbook 中划下章节标题和编号

我正在尝试找到一种方法来在章节标题(包括章节号)下方画一条线。这里提出的解决方案KOMA-章节标题上方和下方的脚本行只是我的情况是章节号在页边空白处。解决方案应该适用于latexmkpdflatexmk

那么有没有简单的方法可以扩展该行以包含章节编号?

这是我的 MWE:

\documentclass{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{blindtext}
\usepackage[default, scale=.90]{opensans} % police Open Sans

%% Chapter number in the margin
\renewcommand*{\chapterformat}{%
  \llap{\thechapter\autodot\enskip}%
}
 
%% Draw a rule of size \textwidth
%% Modification of https://tex.stackexchange.com/questions/273343/koma-script-line-above-and-below-chapter-title
\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}}
\renewcommand\chapterlineswithprefixformat[3]{%
  #2\nobreak%
  \Ifstr{#2}{}{}{\kern-\dp\strutbox}%
  \titlerule\par\nobreak%
  #3%
  \par\nobreak\titlerule%
}
\makeatletter
\renewcommand\chapterlinesformat[3]{%
  \@hangfrom{#2}{#3}%
  \par\nobreak\titlerule%
}
\makeatother
\begin{document}
\blinddocument
\end{document}

答案1

您可以测量章节号的宽度并使规则更长,但要靠左。

\newcommand\titlerule[1][1pt]{%
  \settowidth{\dimen0}{\thechapter\enspace}%
  \hspace*{-\dimen0}\rule{\dimexpr\textwidth+\dimen0}{#1}%
}

完整示例(同一页中的两个章节标题只是为了制作较小的图片)。

\documentclass{scrbook}
%\usepackage[utf8]{inputenc}% no longer necessary
\usepackage[T1]{fontenc}
\usepackage[default, scale=.90]{opensans} % police Open Sans

%% Chapter number in the margin
\renewcommand*{\chapterformat}{%
  \llap{\thechapter\autodot\enskip}%
}
 
%% Draw a rule of size \textwidth
%% Modification of https://tex.stackexchange.com/questions/273343/koma-script-line-above-and-below-chapter-title
\newcommand\titlerule[1][1pt]{%
  \settowidth{\dimen0}{\thechapter\enspace}%
  \hspace*{-\dimen0}\rule{\dimexpr\textwidth+\dimen0}{#1}%
}
\renewcommand\chapterlineswithprefixformat[3]{%
  #2\nobreak%
  \Ifstr{#2}{}{}{\kern-\dp\strutbox}%
  \titlerule\par\nobreak%
  #3%
  \par\nobreak\titlerule%
}
\makeatletter
\renewcommand\chapterlinesformat[3]{%
  \@hangfrom{#2}{#3}%
  \par\nobreak\titlerule%
}
\makeatother

\begin{document}

\chapter{Test}

\begingroup\let\cleardoublepage\relax

\setcounter{chapter}{10}

\chapter{Test}

\endgroup

\end{document}

在此处输入图片描述

相关内容