更改 ToC、LoF 和 LoT 的 ToC 级别

更改 ToC、LoF 和 LoT 的 ToC 级别

我希望我的前言(ToC、LoF、LoT)在目录中与章节(而不是章节)在同一级别显示......

梅威瑟:

\documentclass[]{scrbook}

\KOMAoptions{twoside=false}

\usepackage{tocbibind}

\addtokomafont{partentrypagenumber}{\nullfont}
\addtokomafont{chapterentrypagenumber}{\mdseries}       

\usepackage{tocstyle}
    \usetocstyle{allwithdot}
    \settocstylefeature[-1]{leaders}{\hfill}
    \settocstylefeature[-1]{pagenumberhook}{\nullfont}

\usetocstyle{KOMAlike}
    \usetocstyle{allwithdot}
    \settocstylefeature[-1]{leaders}{\hfill}
    \settocstylefeature[-1]{pagenumberhook}{\nullfont}
\renewcommand*{\addparttocentry}[2]{%
    \addtocentrydefault{part}{\partname\nobreakspace #1}{#2}%
    }%

\begin{document}

\frontmatter

\part*{Front Matter}
    \addcontentsline{toc}{part}{Front Matter}

\tableofcontents
\listoftables
\listoffigures

\mainmatter

\part*{Report}
    \addcontentsline{toc}{part}{Report}

\chapter{Chapter 1}
    \section{Section 1}
    \section{Section 2}
    \section{Section 3}

\appendix

\part*{Appendices}
    \addcontentsline{toc}{part}{Appendices}

\chapter{Appendix 1}
    \section{Appendix Section 1}
    \section{Appendix Section 2}
    \section{Appendix Section 3}

\end{document}

答案1

首先,我将从您的 MWE 中删除软件包tocbibindtocstyle声明:\addcontentsline

\documentclass[
  twoside=false,
  listof=totoc,% add a tocentry for lists like LOF and LOT
  toc=chapterentrywithdots% dots as line filler for chapter entries in TOC
]{scrbook}
\setuptoc{toc}{totoc}% add a tocentry for TOC

\DeclareTOCStyleEntry[
  dynnumwidth,% adjust the space for part numbers in TOC as needed
  entrynumberformat=\partnumberwithprefix,% part number with prefix
  pagenumberformat=\gobble% remove page number of part entries in TOC
]{tocline}{part}
\newcommand\partnumberwithprefix[1]{\partname\nobreakspace#1}
\newcommand\gobble[1]{}

\addtokomafont{chapterentrypagenumber}{\mdseries}
\begin{document}
\frontmatter
\addpart{Front Matter}
\tableofcontents
\listoftables
\listoffigures

\mainmatter
\addpart{Report}
\chapter{Chapter 1}
    \section{Section 1}
    \section{Section 2}
    \section{Section 3}

\appendix
\addpart{Appendices}
\chapter{Appendix 1}
    \section{Appendix Section 1}
    \section{Appendix Section 2}
    \section{Appendix Section 3}
\end{document}

结果:

在此处输入图片描述


如果 TOC、LOF 和 LOT 应该是章节而不是章节,则可以使用lists=leveldown\setuptoc{toc}{leveldown}

\documentclass[
  twoside=false,
  listof=totoc,
  listof=leveldown,% <- added
  toc=chapterentrywithdots
]{scrbook}
\setuptoc{toc}{totoc,leveldown}% <- changed

\DeclareTOCStyleEntry[
  dynnumwidth,
  entrynumberformat=\partnumberwithprefix,
  pagenumberformat=\gobble
]{tocline}{part}
\newcommand\partnumberwithprefix[1]{\partname\nobreakspace#1}
\newcommand\gobble[1]{}

\addtokomafont{chapterentrypagenumber}{\mdseries}
\begin{document}
\frontmatter
\addpart{Front Matter}
\tableofcontents
\listoftables
\listoffigures

\mainmatter
\addpart{Report}
\chapter{Chapter 1}
    \section{Section 1}
    \section{Section 2}
    \section{Section 3}

\appendix
\addpart{Appendices}
\chapter{Appendix 1}
    \section{Appendix Section 1}
    \section{Appendix Section 2}
    \section{Appendix Section 3}
\end{document}

结果:

在此处输入图片描述


但如果你真的希望 TOC、LOF 和 LOT 仍然是章节,但获得像章节一样的 TOC 条目,那么你可以添加

\BeforeTOCHead{%
    \renewcommand\addchaptertocentry[2]
        {\addtocentrydefault{section}{#1}{#2}}%
}

第一个例子。

在此处输入图片描述

代码:

\documentclass[
  twoside=false,
  listof=totoc,
  toc=chapterentrywithdots
]{scrbook}
\setuptoc{toc}{totoc}

\BeforeTOCHead{%
    \renewcommand\addchaptertocentry[2]
        {\addtocentrydefault{section}{#1}{#2}}%
}

\DeclareTOCStyleEntry[
  dynnumwidth,
  entrynumberformat=\partnumberwithprefix,
  pagenumberformat=\gobble
]{tocline}{part}
\newcommand\partnumberwithprefix[1]{\partname\nobreakspace#1}
\newcommand\gobble[1]{}

\addtokomafont{chapterentrypagenumber}{\mdseries}
\begin{document}
\frontmatter
\addpart{Front Matter}
\tableofcontents
\listoftables
\listoffigures

\mainmatter
\addpart{Report}
\chapter{Chapter 1}
    \section{Section 1}
    \section{Section 2}
    \section{Section 3}

\appendix
\addpart{Appendices}
\chapter{Appendix 1}
    \section{Appendix Section 1}
    \section{Appendix Section 2}
    \section{Appendix Section 3}
\end{document}

相关内容