1

I am using the scrbook class and I (for some reasons) need to redefine the commands \thesection and etc. The problem is that this modifies the TOC entries. And I want to restore the TOC entries to the normal format, i.e,

  1. Chapter

1.2 Section

1.2.3 Subsection

but now I just have:

  1. Chapter
  2. Section
  3. Subsection

I solved this problem for the headers by redefining the command \sectionformat, but I did not find any equivalent command to the TOC entries.

      \documentclass[12pt]{scrbook}
       
        
        \usepackage{scrextend}
        
        \usepackage[automark]{scrlayer-scrpage} % instead of fancyhdr
        \renewcommand\thepart{\arabic{part}}
        \renewcommand\thechapter{\arabic{chapter}}
        \renewcommand\thesection{\arabic{section}}
        \renewcommand\thesubsection{\arabic{subsection}}
        \renewcommand\thesubsubsection{\arabic{subsubsection}}
        \renewcommand{\chaptermarkformat}{}
        \renewcommand*\sectionformat{\thechapter.\thesection\enskip}
        \renewcommand*\subsectionformat{\thechapter.\thesection.\thesubsection\enskip}
    \begin{document}
    \tableofcontents
    
    \chapter{One}
    \section{two}
    \subsection{three}
    \chapter{One}
    \section{two}
    \subsection{three}
    \chapter{One}
    \section{two}
    \subsection{three}
    \chapter{One}
    \section{two}
    \subsection{three}

\end{document}
0

1 Answer 1

2

Disclaimer: The desired output seems strange to me and I do not suggest to use different numbers in headings, page header and ToC.

If you want to change the numbers in headings and references redefine \addsectiontocentry and \addsubsectiontocentry to restore the numbers in ToC to the original format:

\documentclass[12pt,numbers=noenddot]{scrbook}
\usepackage[automark]{scrlayer-scrpage}
\renewcommand{\thepart}{\arabic{part}}
%\renewcommand\thechapter{\arabic{chapter}}
\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\arabic{subsection}}
\renewcommand\thesubsubsection{\arabic{subsubsection}}
\renewcommand{\chaptermarkformat}{}
\renewcommand*{\sectionmarkformat}{\thechapter.\thesection\enskip}
\renewcommand*{\subsectionmarkformat}{\thechapter.\thesection.\thesubsection\enskip}

\renewcommand*{\addsectiontocentry}[2]{%
  \IfArgIsEmpty{#1}
    {\addtocentrydefault{section}{#1}{#2}}
    {\addtocentrydefault{section}{\thechapter.#1}{#2}}
}

\renewcommand*{\addsubsectiontocentry}[2]{%
  \IfArgIsEmpty{#1}
    {\addtocentrydefault{subsection}{#1}{#2}}
    {\addtocentrydefault{subsection}{\thechapter.\thesection.#1}{#2}}
}

\begin{document}
\tableofcontents
\chapter{One}
\section{two}
\subsection{three}
\chapter{One}
\section{two}
\subsection{three}
\chapter{One}
\section{two}
\subsection{three}
\chapter{One}
\section{two}
\subsection{three}
\end{document}

If you only want to change the numbers in the headings and not in page header, ToC and references, then you can redefine \sectionformat etc.

\documentclass[12pt,numbers=noenddot]{scrbook}
\usepackage{blindtext}% only for dummy text

\usepackage[automark]{scrlayer-scrpage}
\renewcommand{\thepart}{\arabic{part}\autodot\enskip}

\renewcommand{\sectionformat}{\arabic{section}\autodot\enskip}
\renewcommand{\subsectionformat}{\arabic{subsection}\autodot\enskip}
\renewcommand{\subsubsectionformat}{\arabic{subsubsection}\autodot\enskip}

\setcounter{secnumdepth}{\subsubsectionnumdepth}% numbered subsubsections
\setcounter{tocdepth}{\subsubsectiontocdepth}% ToC entries for subsubsections

\begin{document}
\tableofcontents
\Blinddocument
\Blinddocument
\end{document}

enter image description here

Additional remark: Do not load package scrextend with a KOMA-Script class. Package scrextend provides some basic KOMA-Script features for usage with other classes.

3
  • Thanks @esdd for your answer! In my document, I have some special issues (mostly related with cross-reference and label of parts of texts) and because of these issues, I needed to redefined the commands \thechapter and etc. My question is, with these redefined commands, i.e., \thechapter to \arabic{chapter} and etc., how can I put the ToC entries as \arabic{chapter}.\arabic{section}.\arabic{subsection}\endskip ? Sep 16, 2021 at 14:23
  • @TheEndofTheWorld See my updated answer.
    – esdd
    Sep 16, 2021 at 15:04
  • Works Perfectly! Thank you very much! Sep 16, 2021 at 15:09

You must log in to answer this question.

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