現在、私はこれを持っています:
\documentclass{scrbook}
\usepackage{mwe}
\renewcommand*{\chapterformat}{\mbox{\chapappifchapterprefix{\nobreakspace}\scalebox{3}{\thechapter}\enskip}}
\begin{document}
\chapter{\baselineskip{-1em}This chapter caption has multiple lines and does not fit into a single line}
\lipsum[1]
\end{document}
しかし、私は次のように、章のタイトルをプレフィックスのベースラインに揃えたいのです。
章のタイトルが長すぎると面倒なのはわかっています。しかし、時には 1 行に収まらず、最初の結果が少し気になることもあります。
答え1
2 行の章名の場合は、手動で改行を挿入して を使用します\Longstack
。ただし、3 行になった場合は、どの方法も適切ではないことがわかります。
\documentclass{scrbook}
\usepackage{mwe}
\renewcommand*{\chapterformat}{\mbox{\chapappifchapterprefix{\nobreakspace}\scalebox{3}{\thechapter}\enskip}}
\usepackage{lipsum}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\chapter{\Longstack[l]{This chapter caption has multiple lines\\ and does not fit into a single line}}
\lipsum[1]
\end{document}
また、\Longstack
右端の見出しテキストは右余白に揃えられないことにも注意してください。ここでの出現は単なる偶然です。
最後に、目次を使用する場合は、\chapter
次のようにオプションの引数を使用する必要があります。
\chapter[This chapter caption has multiple lines and does not fit into a single line]%
{\Longstack[l]{This chapter caption has multiple lines\\ and does not fit into a single line}}
スタックが目次に表示されないようにするためです。
答え2
ミニページを使用した自動改行のソリューション:
\chapmark
ミニページには幅の指定が必要です。そこで、定義の大部分を含む新しいコマンドを定義しました。その長さは測定できます。このために、パッケージの 2 つの機能、つまりコマンドと長さの計算機能\chapterformat
を使用しました。ベースラインの方向は、ミニページのオプションの引数によって保護されます。calc
\widthof
b
新しい\Chapter
コマンド (大文字の C を使用) は、オプションの引数で指定する KOMA-Script の拡張機能を使用できる方法で定義されていますが、KOMA-Script オプションがchapterprefix
true に設定されている場合は使用できないことに注意してください。代わりにデフォルト\chapter
を使用する必要があります。例の 11 章と 12 章の下の出力を参照してください。
また、目次の出力はミニページの影響を受けません。以下の出力も参照してください。
さらに、位置合わせを改善するために、 の代わりに\RaggedRight
from を使用しました。ragged2e
\raggedright
\NewDocumentCommand
from の代わりに、パッケージまたはからの空の文字列のテストとともにxparse
古典的な を使用することもできます。\newcommand
(x)ifthen
etoolbox
\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{calc} % provides advanced length computation and command "\widthof"
\usepackage{ragged2e}% better text alignment
\usepackage{xparse}% advanced command definitions
\renewcommand*{\raggedchapterentry}{\RaggedRight}% for chapter TOC entries
\renewcommand*{\raggedsection}{\RaggedRight}% for alignment in titles
\newcommand*{\chapmark}{%
\scalebox{1.5}{\chapappifchapterprefix{\nobreakspace}}\scalebox{3}{\thechapter}\enskip%
}
\renewcommand*{\chapterformat}{%
\begin{minipage}[b]{\widthof{\chapmark}}
\chapmark
\end{minipage}%
}
\NewDocumentCommand\Chapter{o m}{% note the uppercase "C"
\IfValueTF{#1}% optional argument given or not
{% with optional argument:
\chapter[#1]{%
\begin{minipage}[b]{\textwidth-\widthof{\chapmark}}
#2
\end{minipage}}%
}{% without optional argument:
\chapter[#2]{%
\begin{minipage}[b]{\textwidth-\widthof{\chapmark}}
#2
\end{minipage}}%
}
}
\begin{document}
\Chapter{This chapter caption is too long to fit into a single line} % ch. 1
\Chapter[TOC entry for caption with 3 lines] % ch. 2
{This chapter caption is longer than the first one and does not even fit into
two lines}
\setcounter{chapter}{9}
\Chapter{Another chapter caption that is too long to fit into a single line} % ch. 10
\KOMAoption{chapterprefix}{true}
\Chapter[Another TOC entry for caption with 3 lines] % ch. 11
{This chapter caption is also longer than the first one and does not even fit into
two lines}
\chapter{% ch. 12
This caption produced with \textmd{\textbackslash chapter} is too long to fit into
a single line}
\tableofcontents
\end{document}