koma-script/tocstyle:如何删除目录中章节条目缩进?

koma-script/tocstyle:如何删除目录中章节条目缩进?

对于以下代码,我如何删除节条目缩进并按ToC所需输出进行打印?

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

期望输出

在此处输入图片描述

答案1

您可以使用板载命令。

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

答案2

更新:不需要的建议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}

运行三次得到:

在此处输入图片描述


的原始定义\addchaptertocentry

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

如果您仍想使用选项chapteratlistslistof=chaptergapsmall,您可以修补命令\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}

相关内容