Koma スクリプトの章タイトルを章のプレフィックスと揃えるにはどうすればよいですか?

Koma スクリプトの章タイトルを章のプレフィックスと揃えるにはどうすればよいですか?

現在、私はこれを持っています:

\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\widthofb

新しい\Chapterコマンド (大文字の C を使用) は、オプションの引数で指定する KOMA-Script の拡張機能を使用できる方法で定義されていますが、KOMA-Script オプションがchapterprefixtrue に設定されている場合は使用できないことに注意してください。代わりにデフォルト\chapterを使用する必要があります。例の 11 章と 12 章の下の出力を参照してください。

また、目次の出力はミニページの影響を受けません。以下の出力も参照してください。

さらに、位置合わせを改善するために、 の代わりに\RaggedRightfrom を使用しました。ragged2e\raggedright

\NewDocumentCommandfrom の代わりに、パッケージまたはからの空の文字列のテストとともにxparse古典的な を使用することもできます。\newcommand(x)ifthenetoolbox

\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}

最初の章のキャプションの出力

第2章のキャプションの出力

第3章のキャプションの出力

第4章のキャプションの出力

第5章のキャプションの出力

目次の出力

関連情報