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

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}
  • 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
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}

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.