![长居中章节标题的缩进](https://linux22.com/image/367237/%E9%95%BF%E5%B1%85%E4%B8%AD%E7%AB%A0%E8%8A%82%E6%A0%87%E9%A2%98%E7%9A%84%E7%BC%A9%E8%BF%9B.png)
我的出版商希望章节标题居中。有时标题会跨两行,这意味着第一行的标题看起来很像文本。是否可以在左右两侧添加一些缩进?或者将 \textwidth 限制为 0.8\textwidth?
梅威瑟:
\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{blindtext}
\renewcommand*{\raggedchapter}{\centering}
\setkomafont{chapter}{\normalfont}
\begin{document}
\chapter{A very long title with more than one line of text to be typeset in the center with indentation at the left and right}
\blindtext
\end{document}
答案1
您可以重新定义\chapterlinesformat
:
\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{blindtext}
\renewcommand*{\raggedchapter}{\centering}
\setkomafont{chapter}{\normalfont}
\renewcommand*\chapterlinesformat[3]{%
\raggedchapter
\parbox{.8\textwidth}{\raggedchapter#2#3}%
\par\nopagebreak
}
\begin{document}
\chapter{A very long title with more than one line of text to be typeset in the center with indentation at the left and right}
\blindtext
\end{document}
答案2
您可以使用 ragged2e 包来完成此操作:
\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{ragged2e}
\renewcommand*{\raggedchapter}{%
\CenteringLeftskip=2cm plus 2em\relax
\CenteringRightskip=2cm plus 2em\relax
\Centering}
\setkomafont{chapter}{\normalfont}
\begin{document}
\chapter{A very long title with more than one line of text to be typeset in the center with indentation at the left and right}
\blindtext
\end{document}
但我通常更喜欢手动添加新行,而不是更轻松地选择语义上合理的位置:
\chapter[text for the toc]{%
A very long title with more than one line of text \\
to be typeset in the center with indentation at the left and right}