如何手动制作目录

如何手动制作目录

我正在尝试手动制作目录,也就是说我逐个设置每个部分的页面。这是我的目标: 在此处输入图片描述book在这里使用课程。

这是我找到的代码

\documentclass[oneside]{book}
\renewcommand\contentsname{CONTENTS}
\renewcommand\listtablename{LIST OF TABLES}
\renewcommand\listfigurename{LIST OF FIGURES}
\addtocontents{toc}{{\bfseries Contents\hfill Page No.\bigskip\par}}
\addtocontents{lot}{{\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}}
\addtocontents{lof}{{\bfseries No.\hfill Title\hfill\hfill Page No.\bigskip\par}}

\usepackage[titles]{tocloft}
\usepackage{xcolor,xpatch}
\renewcommand\cftbeforechapskip{0ex}
\renewcommand\cftchapfont{\mdseries}
\renewcommand\cftchappagefont{\mdseries}
\renewcommand\cftchappresnum{Chapter~}
\renewcommand\cftchapaftersnum{. }
\newlength\tocindent
\settowidth\tocindent{\cftchapfont\cftchappresnum9\cftchapaftersnum}
\edef\cftchapnumwidth{\the\tocindent}
\edef\cftsecindent{\the\tocindent}
\advance\tocindent2.3em
\edef\cftsubsecindent{\the\tocindent}
\advance\tocindent3.2em
\edef\cftsubsubsecindent{\the\tocindent}
\renewcommand\cftsecdotsep{\cftnodots}
\renewcommand\cftsubsecdotsep{\cftnodots}
\renewcommand\cftsubsubsecdotsep{\cftnodots}
\newcommand\tocmainmatter
{\renewcommand\cftchappagefont{\color{white}}%
}
\xapptocmd\mainmatter{\addtocontents{toc}{\protect\tocmainmatter}}{}{}


\newif\ifschaptertoc
\makeatletter
\renewcommand\@makeschapterhead[1]%
{{\parindent \z@ \centering
    \normalfont
    \interlinepenalty\@M
    \Large \bfseries  #1\par\nobreak
    \vskip 20\p@
}%
\@mkboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}%
\ifschaptertoc
\addcontentsline{toc}{chapter}{#1}%
\fi
}
\makeatother

\usepackage{blindtext}

\begin{document}
\frontmatter

\tableofcontents
\schaptertoctrue

\chapter*{ACKNOWLEDGEMENTS}
\blindtext

\chapter*{ABSTRACT}
\blindtext

\listoftables

\listoffigures

\chapter*{ABBREVIATIONS}
\Blindtext

\chapter*{NOTATIONS}
\Blindtext

\mainmatter

\chapter{INTRODUCTION}
\blindtext

\section{General Background}
\blindtext

\section{Objective}
\blindtext
\subsection{Objective 1}
\blindtext
\subsection{Objective 2}
\blindtext
\subsection{Objective 3}
\blindtext

\section{Scheme}
\blindtext
\end{document}

答案1

这似乎是一个 XY 问题。我不明白你为什么要这样做 (Y),也许知道真正的问题 (X)) 我们可以提出更好的解决方案。尽管如此,“Y”的诀窍很简单:只需打开编译你展示的.toc代码后创建的辅助文件,然后只需“复制、粘贴并根据需要进行修改”即可替换\tableofcontents,或者在空白的 .tex 文档中,然后,手动目录:

姆韦

\documentclass{book}
\pagestyle{empty}
\begin{document}
\noindent{\bfseries{\huge Contents}\hfill Page No.\vspace \bigskipamount \par }
\contentsline {chapter}{ACKNOWLEDGEMENTS}{ii}
\contentsline {chapter}{ABSTRACT}{iii}
\contentsline {chapter}{LIST OF TABLES}{iv}
\contentsline {chapter}{LIST OF FIGURES}{v}
\contentsline {chapter}{ABBREVIATIONS}{vi}
\contentsline {chapter}{NOTATIONS}{viii}
\contentsline {chapter}{\numberline {1}INTRODUCTION}{1}
\contentsline {section}{\numberline {1.1}General Background}{1}
\contentsline {section}{\numberline {1.2}Objective}{3}
\contentsline {subsection}{\numberline {1.2.1}Objective 1}{5}
\contentsline {subsection}{\numberline {1.2.2}Objective 2}{12}
\contentsline {subsection}{\numberline {1.2.3}Objective 3}{15}
\contentsline {section}{\numberline {1.3}Scheme}{16}
\end{document}

编辑2023 年 10 月 30 日

该过程仍然只是从 .toc文件 复制\contentsline并根据您的需要修改参数,但现在内核命令需要四个参数,而不是三个。例如:

\documentclass{book}
\pagestyle{empty}
\begin{document}
\noindent{\bfseries{\huge Contents}\hfill Page No.\vspace \bigskipamount \par }
\contentsline {chapter}{ACKNOWLEDGEMENTS}{ii}{}%
\contentsline {chapter}{ABSTRACT}{iii}{}%
\contentsline {chapter}{LIST OF TABLES}{iv}{}%
\contentsline {chapter}{LIST OF FIGURES}{v}{}%
\contentsline {chapter}{ABBREVIATIONS}{vi}{}%
\contentsline {chapter}{NOTATIONS}{viii}{}%
\contentsline {chapter}{\numberline {1}INTRODUCTION}{1}{}%
\contentsline {section}{\numberline {1.1}General Background}{1}{}%
\contentsline {section}{\numberline {1.2}Objective}{3}{}%
\contentsline {subsection}{\numberline {1.2.1}Objective 1}{5}{}%
\contentsline {subsection}{\numberline {1.2.2}Objective 2}{12}{}%
\contentsline {subsection}{\numberline {1.2.3}Objective 3}{15}{}%
\contentsline {section}{\numberline {1.3}Scheme}{16}{}%
\end{document}

如果您对此不再起作用的原因感到好奇:

 \contentsline {chapter}{ACKNOWLEDGEMENTS}{ii}

但是这个,不添加任何内容,可以工作:

\contentsline {chapter}{ACKNOWLEDGEMENTS}{ii}{}%

原因是这个命令的内核定义已经最近更改因为hyperref将命令重新定义为四个参数,所以如果您使用 hyperref,您的 ToC 将以如下条目结束:

\contentsline {chapter}{ACKNOWLEDGEMENTS}{i}{chapter*.1}%

但是如果您随后从序言中删除了 hyperref,那么您最终会得到\contentsline4 个参数,但原始内核定义只需要 3 个参数,从而导致问题。

新的内核定义解决了加载/卸载问题,hyperref但旧代码却导致错误。这是不从头开始制作 ToC 的另一个原因。

答案2

@Veronica 我也遇到了同样的问题,但我通过如下命令解决了它:

\contentsline {section}{\numberline {1}Introduction}{1}{section.1}
\contentsline {section}{\numberline {2}State of Science and Technology}{3}{section.2}
\contentsline {subsection}{\numberline {2.1}Mathematical Model of Flexible Robotic Manipulators}{1}{subsection.2.1}

相关内容