我也想在章节条目上方和下方添加一条水平线。
在使用scrbook
-class 之前,我使用了 -package 制作的这个简单解决方案titlesec
:
\newpagestyle{headrules}{
\headrule
% for twosided layout, use:
\sethead[\thepage][\chaptertitle][] % even pages (left side of book)
{\chaptertitle}{\sectiontitle}{\thepage} % odd pages (right side of book)
% for onesided layout, use:
% \sethead{\thechapter. \chaptertitle}{}{\thepage} % in this case, the document only has odd pages
}
最小工作示例:
\documentclass{book}
\usepackage[english]{babel}
\usepackage[automark]{scrpage2}
\usepackage[pagestyles]{titlesec}
\usepackage{blindtext}
\titleformat{\chapter}[display]{\fontfamily{pag}\Large\bfseries}{\titlerule[4pt]\chaptertitlename\ \thechapter}{5pt}{\large}[{\titlerule[2pt]}]
\titleformat{\section}{\fontfamily{pag}\normalsize\bfseries}{\thesection}{5pt}{\normalsize}
\titleformat{\subsection}{\fontfamily{pag}\normalsize\bfseries}{\thesubsection}{5pt}{\normalsize}
\titlespacing*{\chapter}{0pt}{30pt}{20pt}
\titlespacing*{\section}{0pt}{20pt}{10pt}
\titlespacing*{\subsection}{0pt}{20pt}{5pt}
\newpagestyle{headrules}{
\headrule
% for twosided layout, use:
\sethead[\thepage][\chaptertitle][] % even pages (left side of book)
{\chaptertitle}{\sectiontitle}{\thepage} % odd pages (right side of book)
% for onesided layout, use:
% \sethead{\thechapter. \chaptertitle}{}{\thepage} % in this case, the document only has odd pages
}
\setlength{\headheight}{1.1\baselineskip} % adjusting the height of head
\pagestyle{headrules} % use this style instead of \pagestyle{plain}
\begin{document}
\blinddocument
\end{document}
截屏:
所以,现在的问题是:我该如何解决这个问题没有还在使用-package 吗?不建议与 KOMA-class 一起titlesec
使用,我更喜欢使用 -class,因为它有很多优点(例如和其他优点)...titlesec
scrbook
book
addchap
我是否必须plain
为此更改页面样式格式?
非常感谢您的帮助!
clemens 提出的以下分离解决方案\chapters
似乎\addchaps
有意义,但在以下最小示例中不起作用(不知道为什么):
\documentclass[chapterprefix=true]{scrbook}
\renewcommand*\chapterheadstartvskip{%
\ifnumbered{chapter}
{\noindent\rule{\linewidth}{4pt}\par\vspace*{-4pt}}
{}%
}
\renewcommand*\chapterheadendvskip{%
\ifnumbered{chapter}
{\vspace*{-4pt}\noindent\rule{\linewidth}{2pt}\par\vspace{\baselineskip}}
{}%
}
\begin{document}
\chapter{Experimental chapter-entry}
\addchap{Experimental addchap-entry}
\end{document}
\chapter
是否有编号并不重要\addchap
- 选定的行在两个选择器中都存在或不存在......
我的思路有错误吗?
解决方案:升级到 KOMA-Script v3.18 也为我带来了解决方案!非常感谢 clemens 和所有帮助我的人!
非常感谢您耐心的帮助!
答案1
更新
使用 KOMA-Script 版本 3.19 或更新版本还有另一种可能性:您可以重新定义新命令\chapterlineswithprefixformat
来插入以下行:
\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}}
\renewcommand\chapterlineswithprefixformat[3]{%
\ifstr{#2}{}{}{\titlerule[4pt]\par}%
#2#3\titlerule[2pt]%
}
梅威瑟:
\documentclass[
chapterprefix=true
]{scrbook}[2015/09/29]% needs version 3.19 or newer
\RedeclareSectionCommand[
beforeskip=0pt,
afterskip=1\baselineskip
]{chapter}
\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}}
\renewcommand\chapterlineswithprefixformat[3]{%
\ifstr{#2}{}{}{\titlerule[4pt]\par\nobreak}%
#2#3\par\nobreak\titlerule[2pt]%
}
\usepackage{blindtext}
\begin{document}
\chapter{Experimental chapter-entry}
\blindtext
\addchap{Experimental addchap-entry}
\blindtext
\chapter*{Experimental chapter*-entry}
\blindtext
\addchap*{Experimental addchap*-entry}
\blindtext
\end{document}
如果这也应该与选项一起使用,chapterprefixline=false
请将以下几行添加到序言中:
\makeatletter
\renewcommand\chapterlinesformat[3]{%
\@hangfrom{#2}{#3}\par\nobreak\titlerule%
}
\makeatother
原始答案
如果仅当写入 时才应插入章节标题上方的行,chapterprefix
则可以在 中插入此行\chapterformat
。 这也适用于\chapter*
和\addchap*
。
\documentclass[chapterprefix=true]{scrbook}
\RedeclareSectionCommand[
beforeskip=0pt,
afterskip=1\baselineskip
]{chapter}
\usepackage{etoolbox}
\newcommand\titlerule[1][1pt]{\noindent\rule{\linewidth}{#1}\par}
\preto\chapterformat{\IfUsePrefixLine{\vspace{-\baselineskip}\titlerule[4pt]}{}}
\preto\chapterheadendvskip{\titlerule[2pt]}
\usepackage{blindtext}
\begin{document}
\chapter{Experimental chapter-entry}
\blindtext
\addchap{Experimental addchap-entry}
\blindtext
\chapter*{Experimental chapter*-entry}
\blindtext
\addchap*{Experimental addchap*-entry}
\blindtext
\end{document}
答案2
尽管其名称如此,但 KOMA-Script 的通常做法是重新定义\chapterheadstartvskip
并\chapterheadendvskip
:
\documentclass[chapterprefix=true]{scrbook}
\renewcommand*\chapterheadstartvskip{\noindent\rule{\linewidth}{4pt}\par}
\renewcommand*\chapterheadendvskip{\noindent\rule{\linewidth}{2pt}\par\vspace{\baselineskip}}
\usepackage{blindtext}
\begin{document}
\blinddocument
\end{document}
定义略有改变,只有章节号符合规则。\vspace*
在正确位置添加 s 会使行更靠近文本:
\renewcommand*\chapterheadstartvskip{%
\ifnumbered{chapter}
{\noindent\rule{\linewidth}{4pt}\par\vspace*{-4pt}}
{}%
}
\renewcommand*\chapterheadendvskip{%
\ifnumbered{chapter}
{\vspace*{-4pt}\noindent\rule{\linewidth}{2pt}\par\vspace{\baselineskip}}
{}%
}