删除目录中的章节编号

删除目录中的章节编号

我正在使用 Matthias Pospiech 的最新版本的 LaTeX 模板,请参阅http://www.matthiaspospiech.de/blog/2016/05/09/latex-thesis-template-3-2-4-released/

在我的 MWE 中,我尝试实现以下目标:我创建了一个章节,\chapter[Chapter 1: Headline]{Headline}并在目录中将其打印为1 Chapter 1: Headline

我想删除第一个1,这样Chapter 1: Headline将组合显示,章节本身的样式在章节开始的页面上,页面标题的样式应该仍然相同。因此,只删除章节编号1而不更改文档中的其他内容。

\documentclass[paper=a4,version=last,english]{scrbook}

\usepackage{templatetools}
\usepackage{lipsum}
\usepackage{babel}
\usepackage[style=apa,backend=biber]{biblatex}
\usepackage[automark,komastyle]{scrpage2}
\usepackage{pageslts}

\ifcsdef{chapter}
    {\usepackage{titlesec}}
    {\usepackage{titlesec} \csundef{chapter}}

\usepackage{titletoc}
\usepackage{pdfpages}

\IfPackageLoaded{scrpage2}{
\IfElseDefined{chapter}{
   \pagestyle{scrheadings}
}{
   \pagestyle{scrplain}
}
\IfElseDefined{chapter}{
   \ohead{\pagemark}
   \ihead{\headmark}
   \ofoot[\pagemark]{}
}{
   \cfoot[\pagemark]{\pagemark}
}
\IfElseDefined{chapter}{
   \automark[section]{chapter}
}{
   \automark[subsection]{section}
}
\IfDefined{chapter}{
   \setheadsepline{.4pt}[\color{black}]
}
}
\IfPackageLoaded{titlesec}{
\titleformat{\chapter}[display]
  {\usekomafont{chapter}\Large \color{black}}
  {\LARGE\MakeUppercase{\chaptertitlename}
   \Huge~\thechapter \filright}
  {1pt}
  {
   \titlerule \vspace{0.9pc}\vspace{-\parskip}
   \filright 
   \IfColorDefined{sectioncolor}{\color{sectioncolor}}{}   
  }
  [\color{black} \vspace{0.9pc} \filright {\titlerule}]
}

\makeatletter
\@ifundefined{frontmatter}{
   \newcommand{\frontmatter}{
      \pagenumbering{roman}
   }
}{}
\@ifundefined{mainmatter}{
   \newif\if@mainmatter\@mainmattertrue
   \newcommand{\mainmatter}{
      \pagenumbering{arabic}
      \setcounter{page}{1}
   }
}{}
\makeatother

\begin{document}
\frontmatter
\IfPackageLoaded{scrpage2}{\pagestyle{scrheadings}}
\tableofcontents

\mainmatter

\addchap{General Introduction}
\lipsum[1]

\chapter[Chapter 1: Headline]{Headline}
\lipsum[3-10]

\end{document}

答案1

请注意,包titletoc和包都不titlesec应与 KOMA-Script 类一起使用。包scrpage2已弃用多年。它的后继者是scrlayer-scrpage

您可以添加

\DeclareTOCStyleEntry[
  numwidth=0pt,
  entrynumberformat=\noentrynumber
]{chapter}{chapter}
\newcommand*\noentrynumber[1]{}
\renewcommand*\chaptermarkformat{}

从目录和页眉中删除章节号。请注意,目录中的章节条目将由包控制tocbasic

删除包装titletoc并使用

\DeclareTOCStyleEntry[
  numwidth=0pt,
  entrynumberformat=\noentrynumber
]{chapter}{chapter}
\newcommand\noentrynumber[1]{}

在此处输入图片描述

在此处输入图片描述

但我认为最好删除章节的可选参数(以及其中的手册编号),并通过更改entrynumberformat章节条目在目录中插入章节前缀:

\DeclareTOCStyleEntry[
  dynnumwidth,
  entrynumberformat=\chapterentrynumber
]{chapter}{chapter}
\newcommand\chapterentrynumber[1]{\def\autodot{:}\chaptername\ #1}
\renewcommand\chaptermarkformat{\chaptername\ \thechapter:\enskip}

然后你必须运行代码三次才能得到:

在此处输入图片描述

代码:

% Disclamer:
% The following code is mainly the MWE from the question.
% Note that you should not use packages titlesec and titletoc
% together with a KOMA-Script class.
% Package `scrpage2` is deprecated. Its successor is scrlayer-scrpage.
% So I do not recommend to use the following code.
\documentclass[paper=a4,version=last,english]{scrbook}

\usepackage{templatetools}
\usepackage{lipsum}
\usepackage{babel}
\usepackage[style=apa,backend=biber]{biblatex}
\usepackage[automark,komastyle]{scrpage2}
\usepackage{pageslts}

\ifcsdef{chapter}
    {\usepackage{titlesec}}
    {\usepackage{titlesec} \csundef{chapter}}

\usepackage{titletoc}
\usepackage{pdfpages}

\IfPackageLoaded{scrpage2}{
\IfElseDefined{chapter}{
   \pagestyle{scrheadings}
}{
   \pagestyle{scrplain}
}
\IfElseDefined{chapter}{
   \ohead{\pagemark}
   \ihead{\headmark}
   \ofoot[\pagemark]{}
}{
   \cfoot[\pagemark]{\pagemark}
}
\IfElseDefined{chapter}{
   \automark[section]{chapter}
}{
   \automark[subsection]{section}
}
\IfDefined{chapter}{
   \setheadsepline{.4pt}[\color{black}]
}
}
\IfPackageLoaded{titlesec}{
\titleformat{\chapter}[display]
  {\usekomafont{chapter}\Large \color{black}}
  {\LARGE\MakeUppercase{\chaptertitlename}
   \Huge~\thechapter \filright}
  {1pt}
  {
   \titlerule \vspace{0.9pc}\vspace{-\parskip}
   \filright 
   \IfColorDefined{sectioncolor}{\color{sectioncolor}}{}
  }
  [\color{black} \vspace{0.9pc} \filright {\titlerule}]
}

\makeatletter
\@ifundefined{frontmatter}{
   \newcommand{\frontmatter}{
      \pagenumbering{roman}
   }
}{}
\@ifundefined{mainmatter}{
   \newif\if@mainmatter\@mainmattertrue
   \newcommand{\mainmatter}{
      \pagenumbering{arabic}
      \setcounter{page}{1}
   }
}{}
\makeatother

\DeclareTOCStyleEntry[% <- added
  dynnumwidth,
  entrynumberformat=\chapterentrynumber
]{chapter}{chapter}
\newcommand\chapterentrynumber[1]{\def\autodot{:}\chaptername\ #1}% <- added
\renewcommand\chaptermarkformat{\chaptername\ \thechapter:\enskip}%<- added

\begin{document}
\frontmatter
\IfPackageLoaded{scrpage2}{\pagestyle{scrheadings}}
\tableofcontents

\mainmatter

\addchap{General Introduction}
\lipsum[1]

\chapter{Headline}% <- changed
\lipsum[3-10]

\end{document}

相关内容