![在目录中添加更多章节和子章节的缩进](https://linux22.com/image/380631/%E5%9C%A8%E7%9B%AE%E5%BD%95%E4%B8%AD%E6%B7%BB%E5%8A%A0%E6%9B%B4%E5%A4%9A%E7%AB%A0%E8%8A%82%E5%92%8C%E5%AD%90%E7%AB%A0%E8%8A%82%E7%9A%84%E7%BC%A9%E8%BF%9B.png)
我想在目录中添加更多章节和小节的缩进,与章节名称对齐,
这是我的代码
\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}