Custom TOC number entering in Koma-Script

koma-scriptscrbooktable of contents

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}

Best Answer

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.

Related Question