0

I need to style the Numbered and Unnumbered Chapter in my Table of Contents, using scrbook, so that:

  1. The Numbered Chapter is in uppercase, in the form of chapterprefix em-dash chaptertitle, e.g. CHAPTER 1 --- FOO.
  2. One of the Unnumbered Chapter, the Abstract (in English), is italicised.

My MWE

%% Preamble %%
\documentclass[12pt,a4paper,chapterprefix=true,headings=twolinechapter,oneside,]{scrbook}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{lipsum}
\usepackage{mathptmx}

% Style Table of Content.
\newcommand\chapterentrynumberformat[1]{\chapapp\ #1}
\RedeclareSectionCommand[
   tocentrynumberformat=\chapterentrynumberformat,
   tocnumwidth= 5em,
]{chapter}

\setkomafont{chapterentrypagenumber}{\nullfont}

\renewcommand\addchaptertocentry[2]{%
 \IfArgIsEmpty{#1}
  {\addtocontents{toc}
   {\protect\begingroup
    \protect\setkomafont{chapterentrypagenumber}{}%
    \protect\KOMAoptions{chapterentrydots}%
   }%
   \addtocentrydefault{chapter}{}{#2}%
   \addtocontents{toc}{\protect\endgroup}%
  }
  {\addtocentrydefault{chapter}{#1}{#2}}%
}

%% Document Parts %%
\begin{document}
\frontmatter
\pagestyle{plain}
\tableofcontents
\addchap{ABSTRAK} % Abstract in language other than English
\lipsum[1]
\addchap{ABSTRACT} % Abstract in English, must be shown italicised in ToC
\lipsum[2]
\mainmatter
\addchap{SOMESTUFFS}
\lipsum[3]
\chapter{FOO}
\section{Bar}
\lipsum[4]
\end{document}

I do appreciate any help. Thanks.

  • I do not really understand the sense of changing the formatting of only one ToC entry. Nevertheless you can use class option headings=optiontotocandhead and \addchap[tocentry=\protect\textit{ABSTRACT}]{ABSTRACT} or you can define a new section command using \DeclareNewSectionCommand and set option tocentryformat to \textit. The last solution would be more nice. – Schweinebacke Sep 11 '17 at 12:12
  • I do not really understand either, but the requirement says so. I assume because there are two versions of abstracts, one in language other than English (the main language of the entire document), and another is the translation to English. The English title of Abstract, then, is italicised to distinguish it as the foreign language -- although the entire text of the abstract in Engish is strangely not italicised. As for your suggestion, how would I do \DeclareNewSectionCommand? I my original MWE, I already declared one for {chapter}. I am confused to be honest. – M. Ridha Siregar Sep 13 '17 at 19:03
  • @Schweinebacke I tried class option headings=optiontotocandhead (changed the headings=twolinechapter in my original MWE with class option you suggested) and \addchap[tocentry=\protect\textit{ABSTRACT}]{ABSTRACT}. That does not work. The entry for ABSTRACT in ToC now shows tocentry=ABSTRACT . . . . . . . . . . (iii). I have no idea on how to define \DeclareNewSectionCommand and set option tocentryformat to \textit. – M. Ridha Siregar Sep 14 '17 at 2:44
  • 1
    My mistake: The \addchap command has to be: \addchap[tocentry=\normalfont\textit{ABSTRACT}]{ABSTRACT} (without \protect but with additional \normalfont because there is no bold italic sans serif font OT1/cmss/bx/it). If you need bold italic sans serif, you need to use another font, e.g., \usepackage[scaled]{helvet} or \usepackage{lmodern} (last one before \usepackage{mathptmx}). – Schweinebacke Sep 14 '17 at 6:15
1

I would use

\usepackage{xpatch}% needed to path \addchaptertocentry

% Style Table of Content.
\setkomafont{chapterentrypagenumber}{\nullfont}
\newcommand\chapterentrynumberformat[1]{\MakeUppercase\chapapp\ #1\kern 0.25em---\kern 0.25em}
\xpatchcmd{\addchaptertocentry}
  {\addtocentrydefault{chapter}{#1}{#2}}
  {\IfArgIsEmpty{#1}
    {\addtocontents{toc}
     {\protect\begingroup
      \protect\setkomafont{chapterentrypagenumber}{}%
      \protect\KOMAoptions{chapterentrydots}%
     }%
     \addtocentrydefault{chapter}{}{\MakeUppercase{#2}}%
     \addtocontents{toc}{\protect\endgroup}%
    }
    {\addtocentrydefault{chapter}{}{\protect\chapterentrynumberformat{#1}\MakeUppercase{#2}}}%
  }{}{\PatchFailed}

With the suggestion of @Schweinebacke (see his comments to the question) and \usepackage[T1]{fontenc}:

\documentclass[
  12pt,a4paper,
  chapterprefix=true,% chapterprefixline does the same
  headings=optiontoheadandtoc,% <- added
  oneside
]{scrbook}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{lipsum}
\usepackage[T1]{fontenc}% <- added
\usepackage{mathptmx}

\usepackage{xpatch}% needed to path \addchaptertocentry

% Style Table of Content.
\setkomafont{chapterentrypagenumber}{\nullfont}
\newcommand\chapterentrynumberformat[1]{\MakeUppercase\chapapp\ #1\kern 0.25em---\kern 0.25em}
\xpatchcmd{\addchaptertocentry}
  {\addtocentrydefault{chapter}{#1}{#2}}
  {\IfArgIsEmpty{#1}
    {\addtocontents{toc}
     {\protect\begingroup
      \protect\setkomafont{chapterentrypagenumber}{}%
      \protect\KOMAoptions{chapterentrydots}%
     }%
     \addtocentrydefault{chapter}{}{\MakeUppercase{#2}}%
     \addtocontents{toc}{\protect\endgroup}%
    }
    {\addtocentrydefault{chapter}{}{\protect\chapterentrynumberformat{#1}\MakeUppercase{#2}}}%
  }{}{\PatchFailed}

%% Document Parts %%
\begin{document}
\frontmatter
\pagestyle{plain}
\tableofcontents
\addchap{ABSTRAK} % Abstract in language other than English
\lipsum[1]
\addchap[tocentry=\textit{ABSTRACT}]{ABSTRACT} % Abstract in English, must be shown italicised in ToC
\lipsum[2]
\mainmatter
\addchap{SOMESTUFFS}
\lipsum[3]
\chapter{FOO}
\section{Bar}
\lipsum[4]
\setcounter{chapter}{9}
\chapter{Chapter with two digit number}
\end{document}

results in

enter image description here


Update

If you are loading package hyperref use command \texorpdfstring to avoid the \MakeUppercase ...ppercaseUnsupportedInPdfStrings error:

\documentclass[
  12pt,a4paper,
  chapterprefix=true,% chapterprefixline does the same
  headings=optiontoheadandtoc,% <- added
  oneside
]{scrbook}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{lipsum}
\usepackage[T1]{fontenc}% <- added
\usepackage{mathptmx}

\usepackage{xpatch}% needed to path \addchaptertocentry
\usepackage{hyperref}

% Style Table of Content.
\setkomafont{chapterentrypagenumber}{\nullfont}
\newcommand\chapterentrynumberformat[1]{\MakeUppercase\chapapp\ #1\kern 0.25em---\kern 0.25em}
\xpatchcmd{\addchaptertocentry}
  {\addtocentrydefault{chapter}{#1}{#2}}
  {\IfArgIsEmpty{#1}
    {\addtocontents{toc}
     {\protect\begingroup
      \protect\setkomafont{chapterentrypagenumber}{}%
      \protect\KOMAoptions{chapterentrydots}%
     }%
     \addtocentrydefault{chapter}{}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
     \addtocontents{toc}{\protect\endgroup}%
    }
    {\addtocentrydefault{chapter}{}{\texorpdfstring{\protect\chapterentrynumberformat{#1}\MakeUppercase{#2}}{#2}}}%
  }{}{\PatchFailed}

%% Document Parts %%
\begin{document}
\frontmatter
\pagestyle{plain}
\tableofcontents
\addchap{ABSTRAK} % Abstract in language other than English
\lipsum[1]
\addchap[tocentry=\textit{ABSTRACT}]{ABSTRACT} % Abstract in English, must be shown italicised in ToC
\lipsum[2]
\mainmatter
\addchap{SOMESTUFFS}
\lipsum[3]
\chapter{FOO}
\section{Bar}
\lipsum[4]
\setcounter{chapter}{9}
\chapter{Chapter with two digit number}
\end{document}
  • This is an excellent solution, esp. when there are two digit chapters. No need to fiddle with tocnumwidth like my previous partial answer. Thank youuu... :-) – M. Ridha Siregar Sep 17 '17 at 18:40
0

I have a partial answer to my own question, i.e., to add the em-dash between the chapterprefix and chaptertitle in Numbered Chapter entries in ToC, and make the chapterprefix uppercase.

In my original MWE

% Style Table of Content.
\newcommand\chapterentrynumberformat[1]{\chapapp\ #1}
\RedeclareSectionCommand[
   tocentrynumberformat=\chapterentrynumberformat,
   tocnumwidth= 5em,
]{chapter}

I append \MakeUppercase before \chapapp (that prints "Chapter"), add the em-dash with some hspace before and after the em-dash. Then I adjust the tocnumwidth attribute of \RedeclareSectionCommandso that the chaptertitle does not overlaps with the em-dash. The MWE now reads

% Style Table of Content.
\newcommand\chapterentrynumberformat[1]{\MakeUppercase\chapapp\ #1\kern 0.25em---\kern 0.25em}
\RedeclareSectionCommand[
   tocentrynumberformat=\chapterentrynumberformat,
   tocnumwidth= 7.5em,
]{chapter}

I am still looking for solution on how to italicise one of the Unnumbered Chapters (i.e. the ABSTRACT).

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.