长居中章节标题的缩进

长居中章节标题的缩进

我的出版商希望章节标题居中。有时标题会跨两行,这意味着第一行的标题看起来很像文本。是否可以在左右两侧添加一些缩进?或者将 \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}

相关内容