对于每个章节我都尝试放置一条双重或三重水平线,从左侧开始并延伸到右对齐的章节标题,如下所示:
================================================================== 第 10 章
我认为我已经找到了创建规则的部分解决方案,但是当我将代码放在 \chaptertitlename \thechapter 之前时,Chapter 一词消失了,章节编号移到了下一行。
以下是我得到的信息:
\documentclass{book}
\usepackage[margin=1in]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\Huge\bfseries\raggedright\sffamily}{\raggedleft\chaptertitlename\ \thechapter}{20pt}
{\Huge}
\newcommand{\chapterrule}{0.4pt} % chapter rule thickness
\newcommand{\chapterrulesep}{5pt} % space between the rules
\newcommand{\chapterruleoffset}{2pt} % distance of the bottom rule from the baseline
\newcommand{\triplerule}[1]{%
\vbox{
\sbox0{ #1 }%
\dimen0=\textwidth
\advance\dimen0 by -\wd0
\noindent
\maketriplerule
\usebox{0}%
}
}
\newcommand{\maketriplerule}{%
\vbox{
\hrule width \dimen0 height \chapterrule
\vskip\chapterrulesep
\hrule height \chapterrule
\vskip\chapterrulesep
\hrule height \dimen0 height \chapterrule
\vskip\chapterruleoffset
}%
}
\begin{document}
\chapter[Test]{Test}
This is a test sentence.
\end{document}
答案1
不确定这是否正是您想要的,但我根据@DavidCarlisle 的代码定义了一个\triplerulefill
命令:\documentclass{book} \usepackage[margin=1in]{geometry} \usepackage{titlesec}
\newcommand\triplerulefill{\leavevmode\leaders\vbox{\hrule width.1pt\kern 5pt\hrule width .1pt\kern 5pt\hrule\kern 3pt}\hfill\kern0pt }
\titleformat{\chapter}[display]
{\normalfont\Huge\bfseries\raggedright\sffamily}{ \triplerulefill\,\chaptertitlename\ \thechapter}{20pt}
{\Huge}
\begin{document}
\chapter[Test]{Test}
This is a test sentence in a Test chapter.
\end{document}
答案2
您有相互冲突的要求:如果您希望距离基线 2pt 并且规则之间有固定的空间,那么您将无法将中间规则相对于 C 居中。
以下解决方案将规则按照规定的彼此距离进行排版,并相对于 C 垂直居中。
\documentclass{book}
\usepackage[margin=1in]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\Huge\bfseries\sffamily}
{\triplerule\chaptertitlename\ \thechapter}
{20pt}
{\Huge}
\newcommand{\triplerule}{%
\leavevmode
\sbox0{C}%
\sbox0{\vbox to \ht0{%
\vfill
\hrule height \chapterrule depth \chapterrule width 4pt
\vskip\chapterrulesep
\hrule height \chapterrule depth \chapterrule
\vskip\chapterrulesep
\hrule height \chapterrule depth \chapterrule
\vfill
}}%
\copy0\leaders\hbox{\kern-1pt\copy0\kern-1pt}\hfill\box0
\enspace
}
\newcommand{\chapterrule}{0.3pt} % chapter rule half thickness
\newcommand{\chapterrulesep}{5pt} % space between the rules
\begin{document}
\chapter[Test]{Test}
This is a test sentence.
\end{document}