1

For the following code, how can I remove section entries indentation and print ToC like the desired output?

\RequirePackage{luatex85}
\documentclass{scrbook}
\renewcommand*{\chapterformat}{CHAPTER~\thechapter:\enskip}
\renewcommand*\raggedchapter{\centering}
\renewcommand\chapterlinesformat[3]{%
    #2\MakeUppercase{#3}% #2 is <CHAPTER1:> and #3 is the title
}
\usepackage[tocflat]{tocstyle}
\renewcommand*{\addchaptertocentry}[2]{%
    \addtocentrydefault{chapter}{CHAPTER\nobreakspace#1}{#2}%
}
\usetocstyle{KOMAlike}


\begin{document}
    \tableofcontents
    \chapter{TITLE}
    \section{Topic 1}
    \subsection{Sub-topic 1}
\end{document}

Desired Output

enter image description here

Diaa
  • 9,599

2 Answers2

4

Update: Suggestion that does not need xpatch

\documentclass
  [listof=totoc]
  {scrbook}[2017/01/03]
\renewcommand*{\chapterformat}{\chaptername~\thechapter:\enskip}
\renewcommand*\raggedchapter{\centering}
\renewcommand\chapterlinesformat[3]{\MakeUppercase{#2#3}}

\newcommand\chapnumintoc[1]{\MakeUppercase{\chaptername}~#1}
\RedeclareSectionCommand[
  tocentrynumberformat=\chapnumintoc,
  tocdynnumwidth
]{chapter}
\RedeclareSectionCommand[tocindent=0pt]{section}
\RedeclareSectionCommand[tocindent=2.3em]{subsection}

\begin{document}
\tableofcontents
\listoftables
\chapter{Title}
\section{Topic 1}
\subsection{Sub-topic 1}
\addchap{Unnumbered Chapter}
\end{document}

Run three times to get:

enter image description here


The original definition of \addchaptertocentry is

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

If you still want to use option chapteratlists or listof=chaptergapsmall etc. you could patch command \addchaptertocentry:

\RequirePackage{luatex85}
\documentclass
  [listof=totoc]
  {scrbook}
\renewcommand*{\chapterformat}{\chaptername~\thechapter:\enskip}
\renewcommand*\raggedchapter{\centering}
\renewcommand\chapterlinesformat[3]{\MakeUppercase{#2#3}}

\usepackage{xpatch}
\xpatchcmd\addchaptertocentry
  {\addtocentrydefault{chapter}{#1}{#2}}
  {\ifstr{#1}{}
    {\addtocentrydefault{chapter}{#1}{#2}}%
    {\addtocentrydefault{chapter}{}{\MakeUppercase{\chaptername}~#1:\enskip#2}}%
  }
  {}{\PatchFailed}

\RedeclareSectionCommand[tocindent=0pt]{section}

\begin{document}
\tableofcontents
\listoftables
\chapter{Title}
\section{Topic 1}
\subsection{Sub-topic 1}
\addchap{Unnumbered Chapter}
\end{document}
esdd
  • 85,675
2

You can use on board commands.

\RequirePackage{luatex85}
\documentclass{scrbook}
\renewcommand*{\chapterformat}{CHAPTER~\thechapter:\enskip}
\renewcommand*\raggedchapter{\centering}
\renewcommand\chapterlinesformat[3]{%
    #2\MakeUppercase{#3}% #2 is <CHAPTER1:> and #3 is the title
}
\renewcommand*{\addchaptertocentry}[2]{%
    \addtocentrydefault{chapter}{CHAPTER\nobreakspace#1}{#2}%
}

\RedeclareSectionCommand[tocindent=0pt]{section}
\RedeclareSectionCommand[tocnumwidth=70pt]{chapter}

\begin{document}
\tableofcontents
\chapter{TITLE}
\section{Topic 1}
\subsection{Sub-topic 1}
\end{document}
Johannes_B
  • 24,235
  • 10
  • 93
  • 248
  • I highly appreciate your unconditional consideration. – Diaa Nov 29 '16 at 18:53
  • I am so sorry for my several questions, but this line \addtocentrydefault{chapter} also prefixes LoF and LoT with CHAPTER. How can I make it only affect normal chapters? – Diaa Nov 29 '16 at 19:24
  • @DiaaAbidou The lines that renew addchaptertocentry, move them after the lists. – Johannes_B Nov 29 '16 at 19:42
  • Many thanks, they made me lose my temper. Have a nice day. – Diaa Nov 29 '16 at 19:45