5

I have a fiction book to typeset and I am using scrbook class as I thought that it is very flexible. For every chapter beginning I am using \chapter{} command and leave the field inside {} empty, so the command gives me only the text "Chapter 1." and so on.

However, if there is no name for a chapter, it does not appear in TOC. Is it possible to make them appear?

I hope this explains what I'm trying to achieve.

EDIT1: I am strongly considering to use memoir class, so if somebody knows how to do this in memoir class, please, let me know.

EDIT2: I just noticed, that with memoir class it happens automatically, but I am still interested in scrbook class hacks.

5

With scrbook you can get what you want with the following:

\documentclass{scrbook}
\renewcommand{\numberline}[1]{\chaptername~#1}
\begin{document}
\tableofcontents
\chapter{\null}
abc
\chapter{\null}
def
\end{document}

I assume that you don't use sections; in that case the trick must be different.


For using also parts, one can take a different approach:

\documentclass{scrbook}
\usepackage{etoolbox}

\makeatletter
\def\part@numberline#1{\partname~#1}
\def\chapter@numberline#1{\chaptername~#1}
\patchcmd{\l@part}{\begingroup}{\begingroup\let\numberline\part@numberline}{}{}
\patchcmd{\l@chapter}{\begingroup}{\begingroup\let\numberline\chapter@numberline}{}{}
\makeatother

\begin{document}
\tableofcontents
\part{\null}
\chapter{\null}
abc
\chapter{\null}
def
\end{document}
  • This works if I am using only chapters. Is it possible to do it if I have parts and chapters? Thanks – gns-ank Aug 10 '12 at 0:12
  • That's an amazing answer... Thank you so much! – gns-ank Aug 10 '12 at 14:33
2

You can use the two lines code before every chapter to do it:

\chapter[]{}
\addcontentsline{toc}{chapter}{\chaptername{} \thechapter}

Minimal example:

\documentclass{scrbook}

\begin{document}
\tableofcontents
\chapter[]{}
\addcontentsline{toc}{chapter}{\chaptername{} \thechapter}

\end{document}

But before every chapter you will not get the word chapter, only the chapter number.

1

And here's a solution for the book document class. It relies on using the tocloft package.

\documentclass{book}
\usepackage{tocloft}
\renewcommand\cftchappresnum{Chapter }
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{}
\chapter{}
\end{document}

enter image description here

0

If that should be done only for chapters you can patch \addchaptertocentry.

\documentclass[toc=flat]{scrbook}
\usepackage{xpatch}
\xpatchcmd{\addchaptertocentry}
  {\addtocentrydefault{chapter}{#1}{#2}}
  {\addtocentrydefault{chapter}{\chaptername~#1}{#2}}
  {}{\PatchFailed}
\begin{document}
\tableofcontents
\chapter{\null}
abc
\chapter{\null}
def
\end{document}

Of course you can do the same for other sectioning levels.

\documentclass[toc=flat]{scrbook}
\usepackage{xpatch}
\xpatchcmd{\addparttocentry}
  {\addtocentrydefault{part}{#1}{#2}}
  {\addtocentrydefault{part}{\partname~#1}{#2}}
  {}{\PatchFailed}
\xpatchcmd{\addchaptertocentry}
  {\addtocentrydefault{chapter}{#1}{#2}}
  {\addtocentrydefault{chapter}{\chaptername~#1}{#2}}
  {}{\PatchFailed}
\begin{document}
\tableofcontents
\part{\null}
\chapter{\null}
abc
\chapter{\null}
def
\end{document}

Result

enter image description here

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.