将文本添加到目录中,不带虚线和行号

将文本添加到目录中,不带虚线和行号

尽管遵循了网上的许多建议,但我还是遇到了以下问题。我正在使用 TeXnicCenter 和 MiKTeX。[我在 Latex 社区论坛上发布了相同的内容]。我还没有使用/尝试过该tocloft软件包。我目前正在使用该类thesis2

目标:在我的目录中,我想要一个没有虚线和页码的文本“章节”。例如,

============================================

Table of Contents

Acknowledgments ................ ii

Abstract ........................ v

Chapter

1 Introduction .................. 1

1.1 Network Design .............. 1

1.1.1 Steiner Tree Problems ..... 2

============================================

试验 1:当我这样做时\addcontentsline{toc}{chapter}{\protect Chapter},它会将所需文本(章节)添加到目录中。但是,虚线和页码仍然存在。

试验2:当我这样做时,也会发生同样的情况\addcontentsline{toc}{chapter}{\protect \numberline{}Chapter}

Q1) 另外,我希望“章节”和“1 简介”之间只有一行间距。目前,我得到的是 2 行间距(例如致谢和摘要之间)。我如何摆脱那 2 行间距并将其改为 1 行间距?

答案1

使用\addtocontents代替\addcontentsline,并根据需要添加正负垂直空间。(注意:我使用了thesis2可用的类文件这里

\documentclass{thesis2}

\begin{document}

\tableofcontents

\frontmatter

\chapter{Acknowledgments}

\chapter{Abstract}

\mainmatter

\addtocontents{toc}{%
 \protect\vspace{1em}% 
 \protect\noindent Chapter\protect\par
 \protect\vspace{-1em}%
}

\chapter{Introduction}

\section{Network design}

\end{document}

答案2

以下是根据建议提供的替代解决方案这里。它更“干净”,因为您不需要明确设置间距和缩进:

\documentclass{article}
\newcommand{\notocnumsection}[1]{
  \bgroup%
  \renewcommand*{\addcontentsline}[3]{\addtocontents{##1}{\protect\contentsline{##2}{##3}{}}}%
  \section{#1}%
  \egroup
}
\begin{document}
\tableofcontents
\section{foo}
This is the foo section.
\notocnumsection{bar}
This is the bar section.
\section{baz}
This is the baz section.
\end{document} 

但是,它并没有满足您对间距的期望。但我认为您应该考虑一次性更改所有章节级目录条目的间距。为此,我认为该tocloft包应该很有用(文档这里)。

相关内容