我正在使用该类编写一篇长篇出版物report
。我正在尝试复制以下目录
我搜索了网络,但很难复制上述目录。我当前目录的 MWE 是
\documentclass[a4paper,12pt]{report}
\usepackage[english]{babel}
\begin{document}
\tableofcontents
\chapter{Example 1}
Example 1
\section{Section example}
Section example
\subsection{Subsection example}
Subsection example
\end{document}
更新
回应 leandriis 的精彩帖子,我怎样才能删除下面目录中分别位于“讨论”和“未来工作”旁边的“第 3 章”和“第 4 章”?
我使用的代码如下所示。
\documentclass{report}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[entryformat=\normalfont,
pagenumberformat=\normalfont,
entrynumberformat={\MakeUppercase{\chaptername~}},
linefill=\TOCLineLeaderFill,
numsep=1em,
beforeskip=0pt plus .2pt,
dynnumwidth]
{tocline}{chapter}
\begin{document}
\tableofcontents
\chapter{Example 1}
Example 1
\chapter{Example 2}
Example 2
\section{Section example}
Section example
\subsection{Subsection example}
Subsection example
\chapter{Discussion}
\chapter{Future work}
\end{document}
答案1
为什么不使用该tocloft
包?
% reptocprob.tex SE 599046
\documentclass{report}
\usepackage{tocloft}
\usepackage{comment}
%\begin{comment}
\renewcommand{\cftchapdotsep}{\cftdotsep} % dots after chapter entries
\setlength{\cftchapnumwidth}{8em} % increase space for chapter numbers
\renewcommand{\cftchappresnum}{CHAPTER } % put this before chapter numbers
%\end{comment}
\begin{document}
\tableofcontents
\chapter{Example 1}
Example 1
\chapter{Example 2}
Example 2
\section{Section example}
Section example
\subsection{Subsection example}
Subsection example
\addtocontents{toc}{\protect\renewcommand{\protect\cftchappresnum}{}}
\addtocontents{toc}{\setlength{\cftchapnumwidth}{0pt}}
%\addtocontents{toc}{\protect\renewcommand{\thechapter{}}}
\renewcommand{\thechapter}{}
\chapter{Discussion} % prints Chapter and Discussion and adds to the ToC
\chapter*{Future work} % prints Future work
\addcontentsline{toc}{chapter}{Future work} % adds Future work to the ToC
\end{document}
我不确定您如何在文档中编码“讨论”和“未来工作”章节,因此我在文档和目录中给出了两种处理这些章节的方法。
答案2
在该包的帮助下tocbasic
:
\documentclass{report}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[entryformat=\normalfont,
pagenumberformat=\normalfont,
entrynumberformat={\MakeUppercase{\chaptername~}},
linefill=\TOCLineLeaderFill,
numsep=1em,
beforeskip=0pt plus .2pt,
dynnumwidth]
{tocline}{chapter}
\begin{document}
\tableofcontents
\chapter{Example 1}
Example 1
\chapter{Example 2}
Example 2
\section{Section example}
Section example
\subsection{Subsection example}
Subsection example
\end{document}
\documentclass{report}
\usepackage{hyperref}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[entryformat=\normalfont,
pagenumberformat=\normalfont,
entrynumberformat={\MakeUppercase{\chaptername~}},
linefill=\TOCLineLeaderFill,
numsep=1em,
beforeskip=0pt plus .2pt,
dynnumwidth]
{tocline}{chapter}
\begin{document}
\tableofcontents
\chapter{Example 1}
Example 1
\chapter{Example 2}
Example 2
\section{Section example}
Section example
\subsection{Subsection example}
Subsection example
\chapter*{Discussion}\label{ch:discussion}
\addcontentsline{toc}{chapter}{\nameref{ch:discussion}}
\chapter*{Future work}\label{ch:future-work}
\addcontentsline{toc}{chapter}{\nameref{ch:future-work}}
\end{document}