3

I currently have this:

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

prefix and title aligned with first line only

But what I want to have the chapter title aligned with baseline of the prefix similar to this:

What I want to have

I know that to long chapter titles are a pain. But sometimes, they do not fit in a single line and I consider the first result a bit disturbing.

1

2 Answers 2

4

Using a \Longstack will work for a two line chapter name, with breaks inserted manually. If you get to three lines, though, no method will prove suitable to look at.

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

enter image description here

Note also, the \Longstack will not align the right-edge heading text on the right margin. It's appearance here is merely fortuitous.

Lastly, if you wish to use a table of contents, you will need to use the optional argument of \chapter as such:

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

to avoid the stack showing up in the toc.

3

A solution with automatic line breaking using minipages:

Minipages need a width specification. Thus I defined a new command \chapmark containing most of the \chapterformat definition, whose length I can measure. For this I used two features of package calc: the command \widthof and the possibility to make computations of lengths. The baseline orientation is safed by the optional b argument of the minipages.

The new \Chapter command (with uppercase C) is defined in a way that you can use the enhanced features of KOMA-Script to be given in the optional argument, but note, that it cannot be used with the KOMA-Script option chapterprefix set to true. The default \chapter must be used then instead, cf. output below of chapters 11 and 12 in the example.

Also the output for the Table of Contents is not influenced by the minipages, see output below, as well.

Additionally I used \RaggedRight from ragged2e as replacement of \raggedright for better alignment.

Instead of \NewDocumentCommand from xparse I could have used also a classical \newcommand together with tests for empty strings from packages (x)ifthen or 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}

output of caption for first chapter

output of caption for second chapter

output of caption for third chapter

output of caption for fourth chapter

output of caption for fifth chapter

output of Table of Contents

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .