我正在使用 titlesec 来生成章节标题,代码如下:
\titleformat{\chapter}[display]
{\bfseries\huge\sc}
{\sc\filright\chaptertitlename~\thechapter}
{0ex}
{\titlerule
\vspace{0ex}%
\filleft}
[\vspace{0ex}]
现在它工作正常,但我想强制它只换行到行的右侧,比如说行的三分之二。这是为了让我的标题很长时看起来更美观。
当我强制换行时,它工作正常\chapter{Test with a title that is\\too long for one line}
,但我遇到了两个问题。首先,fancyhdr 标题最终超过两行。其次,行与行之间的间隙太长。有什么建议吗?
答案1
您可以将标题包裹在 中minipage
。除非您发布负责的代码,否则间距是无济于事的。我添加了间距以防止标题实际上从其字母顶部悬挂在规则上。
请注意,\bfseries
只有当您选择具有粗体小型大写字母的非默认字体时,才会有效。无论如何,\sc
不应在 LaTeX 2e 中使用。改用\scshape
。否则,\bfseries
即使您选择具有粗体小型大写字母的非默认字体,也不会产生任何效果。
\documentclass[a4paper]{book}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\bfseries\huge\scshape}% note that \bfseries has no effect with the default fonts
{\filright\chaptertitlename~\thechapter}
{0ex}
{\titlerule
\vspace{1ex}%
\filleft\begin{minipage}{.67\textwidth}}
[\end{minipage}]
\begin{document}
Some text.
\chapter{Bulbous Brandishes Burnish Bournemouth Busily}
Some more.
\chapter{Aardvark Antics Anticipate Angelic Adventures After Arctic Advance}
Yet further stuff.
\end{document}
从美学角度来看,手动在合理的位置断行几乎肯定是更好的选择,甚至可能缩写标题:
\documentclass[a4paper]{book}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\bfseries\huge\scshape}% note that \bfseries has no effect with the default fonts
{\filright\chaptertitlename~\thechapter}
{0ex}
{\titlerule
\vspace{1ex}%
\filleft}
\begin{document}
Some text.
\chapter[Bulbous Brandishes Burnish Bournemouth Busily]{Bulbous\\ Brandishes Burnish\\Bournemouth Busily}
Some more.
\chapter[Aardvark Antics Anticipate Angelic Adventures]{Aardvark Antics\\Anticipate Angelic\\Adventures After\\Arctic Advance}
Yet further stuff.
\newpage And more.
\end{document}