在目录中添加更多章节和子章节的缩进

在目录中添加更多章节和子章节的缩进

我想在目录中添加更多章节和小节的缩进,与章节名称对齐,

在此处输入图片描述 进入这个 在此处输入图片描述

这是我的代码

\documentclass[a5paper,11pt]{book}
\usepackage{newtxtext,newtxmath}
\usepackage[margin=1.5cm, inner=2.5cm]{geometry}
\usepackage{tocbasic}
\usepackage[bookmarks=true]{hyperref}% load as last package

\DeclareTOCStyleEntry[
linefill=\bfseries\TOCLineLeaderFill,
beforeskip=0pt,
entrynumberformat=\chapterprefixintoc,
dynnumwidth
]{tocline}{chapter}

\newcommand*\chapterprefixintoc[1]
{\MakeUppercase{\chaptername}~#1\enskip}


\begin{document}
    \cleardoublepage
    \phantomsection\addcontentsline{toc}{chapter}{CONTENTS}
    \tableofcontents

    \chapter{PENDAHULUAN}
    contents...
    \section{Latar Belakang}
    contents...
    \subsection{ABCD}
    contents
    \subsection{EFGH}
    ...
    \section{Rumusan Masalah}
    \vspace{0.3cm}
    blablabla
    \section{Tujuan Penulisan}
    \vspace{0.25cm}
    blablabla..

    \chapter{DASAR TEORI}
    contents...
    \chapter{PEMBAHASAN}
    contents...
    \chapter{PENUTUP}
    contents...
    \chapter*{BIBLIOGRAPHY}
    \addcontentsline{toc}{chapter}{BIBLIOGRAPHY}
    contents
\end{document}

怎么做?

答案1

numwidth您可以对目录中的章节和部分使用固定值indent

\documentclass[a5paper,11pt]{book}
\usepackage{newtxtext,newtxmath}
\usepackage[margin=1.5cm, inner=2.5cm]{geometry}
\usepackage{tocbasic}
\usepackage[bookmarks=true]{hyperref}% load as last package

\newcommand*\chapternumwidthintoc{7em}
\newcommand*\chapterprefixintoc[1]
  {\MakeUppercase{\chaptername}~#1\enskip}
\DeclareTOCStyleEntry[
  linefill=\bfseries\TOCLineLeaderFill,
  beforeskip=0pt,
  entrynumberformat=\chapterprefixintoc,
  numwidth=\chapternumwidthintoc,
]{tocline}{chapter}
\DeclareTOCStyleEntry[
  indent=\chapternumwidthintoc
]{tocline}{section}
\DeclareTOCStyleEntry{tocline}{subsection}

\begin{document}
  \cleardoublepage
  \phantomsection\addcontentsline{toc}{chapter}{CONTENTS}
  \tableofcontents

  \chapter{PENDAHULUAN}
  contents...
  \section{Latar Belakang}
  contents...
  \subsection{ABCD}
  contents
  \subsection{EFGH}
  ...
  \section{Rumusan Masalah}
  \vspace{0.3cm}
  blablabla
  \section{Tujuan Penulisan}
  \vspace{0.25cm}
  blablabla..

  \chapter{DASAR TEORI}
  contents...
  \chapter{PEMBAHASAN}
  contents
  \chapter{PENUTUP}
  contents
  \chapter*{BIBLIOGRAPHY}
  \addcontentsline{toc}{chapter}{BIBLIOGRAPHY}
  contents
\end{document}

结果:

在此处输入图片描述


如果你仍然想使用dynnumwidth对于章节条目:

警告:以下建议使用内部命令,该命令将来可能会更改或删除。因此代码将来可能会中断。

\documentclass[a5paper,11pt]{book}
\usepackage{newtxtext,newtxmath}
\usepackage[margin=1.5cm, inner=2.5cm]{geometry}
\usepackage{tocbasic}
\usepackage[bookmarks=true]{hyperref}% load as last package

\DeclareTOCStyleEntry[
linefill=\bfseries\TOCLineLeaderFill,
beforeskip=0pt,
entrynumberformat=\chapterprefixintoc,
dynnumwidth
]{tocline}{chapter}

\newcommand*\chapterprefixintoc[1]
{\MakeUppercase{\chaptername}~#1\enskip}

\makeatletter
\AtBeginDocument{%
  \DeclareTOCStyleEntry[%
    indent=\ifundefinedorrelax{scr@dte@chapter@lastmaxnumwidth}
      {1.5em}
      {\scr@dte@chapter@lastmaxnumwidth}%
  ]{tocline}{section}
  \DeclareTOCStyleEntry{tocline}{subsection}
}
\makeatother


\begin{document}
  \cleardoublepage
  \phantomsection\addcontentsline{toc}{chapter}{CONTENTS}
  \tableofcontents

  \chapter{PENDAHULUAN}
  contents...
  \section{Latar Belakang}
  contents...
  \subsection{ABCD}
  contents
  \subsection{EFGH}
  ...
  \section{Rumusan Masalah}
  \vspace{0.3cm}
  blablabla
  \section{Tujuan Penulisan}
  \vspace{0.25cm}
  blablabla..

  \chapter{DASAR TEORI}
  contents...
  \chapter{PEMBAHASAN}
  contents
  \chapter{PENUTUP}
  contents
  \chapter*{BIBLIOGRAPHY}
  \addcontentsline{toc}{chapter}{BIBLIOGRAPHY}
  contents
\end{document}

运行三次即可获得

在此处输入图片描述

章节编号较大的示例:

在此处输入图片描述

答案2

以下用途tocloft实现所需的对齐(而不是tocbasic)。不过,格式保持不变,从上下文中应该可以清楚看出。

在此处输入图片描述

\documentclass{book}

\usepackage{tocloft,lipsum}
\usepackage[bookmarks=true]{hyperref}% load as last package

\setlength{\cftbeforechapskip}{0pt}
\renewcommand{\cftchappresnum}{CHAPTER~}
\settowidth{\cftchapnumwidth}{\cftchapfont CHAPTER~XX}
\renewcommand{\cftchapleader}{\cftchapfont \cftdotfill{\cftsecdotsep}}
\setlength{\cftsecindent}{\cftchapnumwidth}
\setlength{\cftsubsecindent}{\dimexpr\cftsecindent+\cftsecnumwidth}

\begin{document}

\phantomsection\addcontentsline{toc}{chapter}{CONTENTS}
\tableofcontents

\chapter{PENDAHULUAN}\lipsum[1]
\section{Latar Belakang}\lipsum[2]
\subsection{ABCD}\lipsum[3]
\subsection{EFGH}\lipsum[4]
\section{Rumusan Masalah}\lipsum[5]
\section{Tujuan Penulisan}\lipsum[6]

\chapter{DASAR TEORI}\lipsum[7]
\chapter{PEMBAHASAN}\lipsum[8]
\chapter{PENUTUP}\lipsum[9]
\chapter*{BIBLIOGRAPHY}
\addcontentsline{toc}{chapter}{BIBLIOGRAPHY}\lipsum[10]

\end{document}

相关内容