How to format a single entry in the table of contents?

For example, how to add some horizontal space to indent some specific line, including the section number?

ps: I know that I can edit the toc file but to do that any time is boring.

  • untestet: \addtocontents{toc}{\protect\addvspace{1cm}} – Johannes_B Oct 28 '14 at 17:45
  • @Johannes_B, it is inserting vertical space. I'd like to format the entry with horizontal space. – Sigur Oct 28 '14 at 17:49
  • \documentclass{report} \begin{document} \tableofcontents \chapter{tester} \addcontentsline{toc}{chapter}{\hspace{1cm}\protect\numberline{\thechapter}Text} \end{document} – Johannes_B Oct 28 '14 at 17:54

Quickly defining a new package to keep the preamble clean. You now have the command \emphchapter taking a mandatory argument, and an optional for the toc if needed. There is a starred variant as well, setting an unnumbered chapter with indent to the toc. After loading the package, you can use \setkomafont{emphfont} or addtokomafont{emphfont} to format the toc entry. The indent can be changed by using the usual setlength to length emphindent.

Patching arguments inside macros can be troublesome, you can use package etoolbox and package regexpatch. Examples can be found at Patching arguments inside a macro

Setting the color to blue using addtokomafont gives something like this:


\ProvidesPackage{emphchapter}[2014/10/29 TeX.SX demo package]



\NewDocumentCommand{\emphchapter}{ s o m }{
\typeout{starred emphchapter}
\typeout{numbered emphchapter}


\emphchapter[optional numbered emph]{emphchapter}
\chapter{behind emphchapter}
\chapter{before starred}
\emphchapter*{starred emphchapter}
\emphchapter*[optional starred entry]{starred emphchapter with optional}

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.