8

i have to adhere to a style guide which dictates newline after a chapter/section/etc number, i.e. instead of the usual

1.2 Heading

its supposed to be

1.2
Heading

This has to work for both the headings themselves and for the TOC. So far i'm using an ugly clutch by simply writing \section{\\Heading}, which causes some problems, e.g. with the hyperref package. I'm using KOMA-Script (scrreprt), and tried solving this by redefining \sectionformat, which sadly ignores any \newline commands. Is there a clean way to achieve this? I know there is the twolinechapter option which kind of solves it for the chapter headings, although not for the TOC or any other sectioning commands.

Thanks in advance!

EDIT: I found another clutch, which works for the headings and is probably also applicable in some way to the TOC (don't know how to format TOC items jet, will try to find out):

\renewcommand*{\chapterformat}{\makebox[0pt][l]{\raisebox{17.5pt}{\thechapter}}}

This simply raises the numbering, and the \makebox avoids the indenting (negative \vspace / \hspace doesn't work for some reason). Doesn't feel right, but at least better than a newline the beginning of the heading itself.

EDIT A minimal Example of my current method:

\documentclass{scrreprt}
\usepackage{blindtext}
% Styling the Headings
\renewcommand*{\chapterformat}{\makebox[0pt][l]{\raisebox{17.5pt}{\thechapter}}}
\renewcommand*{\sectionformat}{\makebox[0pt][l]{\raisebox{17.5pt}\thesection}}
\renewcommand*{\subsectionformat}{\makebox[0pt][l]{\raisebox{12pt}\thesubsection}}

\begin{document}
\tableofcontents
\blinddocument  
\end{document}

Now all that remains is Styling the TOC. Is there a similar version of \chapterformat (etc.) for the TOC? I know I can redefine the TOC indents with \RedeclareSectionCommand, and set different toc styles. But nothing similar to what I want to achieve.

  • KOMA are nice classes but, if you have to meet a lot of specific formatting requirements, you would be much better using a standard class. Either way, a complete small document we can compile (i.e. code) would make it much easier to help. – cfr Jul 16 '15 at 0:11
  • @cfr Actually i've found them to be rather flexible for the most part. There are hooks for almost everything I need. All that remains now is styling the TOC. Added a minimal example of my current method. – Richard Jul 16 '15 at 7:44
  • 1
    It depends what you need. Often style requirements for theses require things which fly in the face of good typography. Since KOMA is based on the idea of such typography, you have to keep overriding it and it is easier if you don't have to. If the requirements are more in line with KOMA's approach, then it will work nicely. However, I understand that custom section headings are a bit of a pain in KOMA. Whereas a standard class and titlesec is pretty straightforward. – cfr Jul 16 '15 at 11:38
7

Second Update

Since version 3.20 you can use option tocbreakafternumber in \RedeclareSectionCommands to get a break after the sectioning numbers TOC.

\documentclass{scrreprt}[2016/04/09]

\RedeclareSectionCommands[
  tocbreakafternumber,% <-
  tocindent=0pt
]{chapter,section,subsection,subsubsection}

\renewcommand\chapterlinesformat[3]{\ifstr{#2}{}{}{#2\\*}#3}
\renewcommand*{\sectionlinesformat}[4]{%
  \hspace*{#2}%
  \parbox{\dimexpr\linewidth-#2\relax}{\raggedsection
    \ifstr{#3}{}{}{#3\\}%
    #4}%
}

\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\listoffigures
\Blinddocument
\begin{figure}%
  Figure
\caption{A Figure}%
\end{figure}
\end{document}

The result is the same as in the pictures below.


Update

Since version 3.19 the recommended way to change the order or the layout of the sectioning numbers and text is redefining commands \chapterlinesformat, \chapterlineswithprefixformat, \sectionlinesformat and \sectioncatchphraseformat.

Additional I have tested the hack/workaround in my original answer for the TOC with the pre-release of the next KOMA-Script version (3.20). With this upcoming version simple redefining \numberline has no effect. You could appended code to \numberline but at the moment I would suggest to redefine \addtocentrydefault. Maybe in the future there will be a special tocstyle that defines your needed style for the toc entries automatically.

\documentclass[toc=flat]{scrreprt}[2015/10/03]

\renewcommand\chapterlinesformat[3]{\ifstr{#2}{}{}{#2\\*}#3}

\renewcommand*{\sectionlinesformat}[4]{%
  \hspace*{#2}%
  \parbox{\dimexpr\linewidth-#2\relax}{\raggedsection
    \ifstr{#3}{}{}{#3\\}%
    #4}%
}

\renewcommand\addtocentrydefault[3]{%
  \ifstr{#2}{}{%
    \addcontentsline{toc}{#1}{\protect\nonumberline#3}%
  }{%
    \addcontentsline{toc}{#1}{\protect\nonumberline#2\\*#3}%
  }%
}

\usepackage{blindtext}
\begin{document}
\tableofcontents
\listoffigures
\Blinddocument
\begin{figure}%
  Figure
\caption{A Figure}%
\end{figure}
\end{document}

enter image description here

enter image description here


Original answer:

Somebody has asked Markus Kohm a similar question. So there is now a suggestion for the headings on the KOMA-Script website (German):

\documentclass[chapterprefix]{scrreprt}
\renewcommand*{\chapterformat}{\thechapter\autodot}
\RedeclareSectionCommand[innerskip=0pt]{chapter}
\makeatletter
\renewcommand*{\raggedsection}{\raggedright\renewcommand*{\@hangfrom}[1]{##1\\*}}
\makeatother

\usepackage{mwe}
\begin{document}
\Blinddocument
\end{document}

Note: This code is a workaround and uses KOMA-Script internals. It works with the current version 3.18 But maybe it will not work with future releases.

Additionally here is a workaround/hack for the table of contents also based on an idea of Markus:

\documentclass[chapterprefix,
  toc=flat
]{scrreprt}

\renewcommand*{\chapterformat}{\thechapter\autodot}
\RedeclareSectionCommand[innerskip=0pt]{chapter}
\makeatletter
\renewcommand*{\raggedsection}{\raggedright\renewcommand*{\@hangfrom}[1]
{##1\\*}}
\makeatother

\BeforeStartingTOC[toc]{\renewcommand*{\numberline}[1]{#1\\*}}
\RedeclareSectionCommands[tocnumwidth=0pt]{chapter,section,subsection}

\usepackage{blindtext}
\begin{document}
\tableofcontents
\listoffigures
\Blinddocument
\begin{figure}%
  Figure
\caption{A Figure}%
\end{figure}
\end{document}

enter image description here

Or without toc=flat:

enter image description here

  • Nice, thanks. Apparently there will also be a proper way in a future version? – Richard Jul 17 '15 at 12:02
  • Yes, but I think only for the headings. See this comment by Markus. Unfortunaly sourceforge (with the beta of the upcoming version) is down. So I can not test this new code. – esdd Jul 17 '15 at 12:22
  • @Richard In KOMA-Script version 3.20 there will be also a proper way for the TOC. – esdd Apr 10 '16 at 15:41
  • Meanwhile you do not longer need to use a pre-release. – Schweinebacke Feb 10 '17 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.