KOMA-script: Add word "Part" and "Chapter" in ToC

Here is another suggestion that still works if there is an unnumbered chapter or an unnumbered part or an appendix.

\documentclass[
  chapterprefix,
  %numbers=noenddot,
  %toc=indentunnumbered,
  %listof=totoc,
  %listof=chapterentry
]{scrbook}

\usepackage[english]{babel}

\RedeclareSectionCommand[
    tocnumwidth=4em
]{part}
\RedeclareSectionCommand[
    tocnumwidth=6em
]{chapter}
\RedeclareSectionCommand[
    tocindent=6em
]{section}
\RedeclareSectionCommand[
    tocindent=8em
]{subsection}

\let\oldaddchaptertocentry\addchaptertocentry
\renewcommand{\addchaptertocentry}[2]{%
  \ifstr{#1}{}{%
    \oldaddchaptertocentry{#1}{#2}}{%
    \oldaddchaptertocentry{\chapapp{} #1}{#2}%
}}
\let\oldaddparttocentry\addparttocentry
\renewcommand{\addparttocentry}[2]{%
  \ifstr{#1}{}{%
    \oldaddparttocentry{#1}{#2}}{%
    \oldaddparttocentry{\partname{} #1}{#2}%
}}

\usepackage{blindtext}
\begin{document}
\frontmatter
\tableofcontents
\listoftables
\chapter{This is a chapter in frontmatter}
\mainmatter
\part{This is a part}
\blinddocument
\begin{table}%
  \begin{tabular}{l}
  \Huge X
  \end{tabular}
\caption{A table}
\end{table}
\addchap{This is an unnumbered chapter}
\addsec{This is an unnumbered section}
\appendix
\blinddocument
\end{document}

Result:

enter image description here


Update using KOMA-Script Version 3.20 (or newer)

\documentclass[chapterprefix]{scrbook}[2016/05/10]

\newcommand\partentrynumberformat[1]{\partname\ #1}
\RedeclareSectionCommand[
  tocentrynumberformat=\partentrynumberformat,
  tocnumwidth=4em
]{part}

\newcommand\chapterentrynumberformat[1]{\chapapp\ #1}
\RedeclareSectionCommand[
    tocentrynumberformat=\chapterentrynumberformat,
    tocnumwidth=5.5em
]{chapter}

\RedeclareSectionCommand[tocindent=5.5em]{section}
\RedeclareSectionCommand[tocindent=7.8em]{subsection}

\usepackage{blindtext}
\begin{document}
\frontmatter
\tableofcontents
\listoftables
\chapter{This is a chapter in frontmatter}
\mainmatter
\part{This is a part}
\blinddocument
\begin{table}%
  \begin{tabular}{l}
  \Huge X
  \end{tabular}
\caption{A table}
\end{table}
\addchap{This is an unnumbered chapter}
\addsec{This is an unnumbered section}
\appendix
\blinddocument
\end{document}

enter image description here


\documentclass[chapterprefix]{scrbook}

\usepackage[english]{babel}

\renewcommand*{\addparttocentry}[2]{%
  \addtocentrydefault{part}{\partname\nobreakspace #1}{#2}%
}%

\makeatletter

\renewcommand*{\addchaptertocentry}[2]{%
  \addtocentrydefault{chapter}{\chaptername\nobreakspace #1}{#2}%
  \if@chaptertolists
    \doforeachtocfile{%
      \iftocfeature{\@currext}{chapteratlist}{%
        \addxcontentsline{\@currext}{chapteratlist}[{#1}]{#2}%
      }{}%
    }%
    \@ifundefined{float@addtolists}{}{\scr@float@addtolists@warning}%
  \fi
}

\makeatother

\usepackage[tocindentauto]{tocstyle}
\usetocstyle{KOMAlike}

\begin{document}

\tableofcontents

\part{This is a part}
\chapter{This is a chapter}
\section{This is a section}

\end{document}

enter image description here

Do not forget to run LaTeX at least three times when you are using the tocindentauto option from the tocstyle package (see p. 3 of the manual):

With option tocindentauto all widths at the TOCs are calculated by tocstyle. The calculation of the width needs at least one LaTeX run with all TOC entries. So you need at least three LaTeX runs


Here is a solution

\documentclass[chapterprefix]{scrbook}

\usepackage[english]{babel}
\makeatletter
\let\oldaddchaptertocentry\addchaptertocentry
\renewcommand{\addchaptertocentry}[2]{%
\oldaddchaptertocentry{}{\@chapapp{} #1. #2}}
\let\oldaddparttocentry\addparttocentry
\renewcommand{\addparttocentry}[2]{%
\oldaddchaptertocentry{}{\partname{} #1. #2}}
\makeatother
\begin{document}

\tableofcontents

\part{This is a part}
\chapter{This is a chapter}
\section{This is a section}

\part{This is a part}
\chapter{This is a chapter}
\section{This is a section}
\appendix

\part{This is a part}
\chapter{This is a chapter}
\section{This is a section}
\end{document}

enter image description here