我正在修改序言中的报告格式,我需要将目录中多行标题的以下几行(红色圆圈部分)从第一行缩进 0.25 英寸(悬挂缩进 0.25 英寸)。从执行阅读一点看起来使用\cftchapnumwidth
fromtocloft
可能是答案,但\setlength{\cftchapnumwidth}{0.25in}
似乎没有改变任何东西。有人知道如何实现这一点吗?
生成该代码的 LaTeX 代码是:
%Preamble
\documentclass[10pt, letterpaperpaper,]{report}\usepackage{setspace}\doublespacing %Double Spacing
\usepackage{sectsty}\allsectionsfont{\normalsize} % Make all font size 12
\usepackage[hidelinks]{hyperref}
\usepackage[left = 1in, right = 1in, top = 1in, bottom = 1in]{geometry}
%Table of Contents, List of Tables, List of Figures
\usepackage[titles]{tocloft} %Load package for customizing table of contents/lists/figures (Adding titles makes it so that they are formatted the same as chapter titles)
\renewcommand{\contentsname}{Table of Contents} %Rename Contents to Table of Contents
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} % dots for chapters in table of contents
\renewcommand{\cfttoctitlefont}{\normalsize\bfseries} %Bold faced normal size font for title of Table of Contents
\renewcommand{\cftloftitlefont}{\normalsize\bfseries} %Bold faced normal size font for title of List of Tables
\renewcommand{\cftlottitlefont}{\normalsize\bfseries} %Bold faced normal size font for List of Tables
\renewcommand{\cftchapfont}{\normalsize} %Unbold chapter titles in table of contents
\renewcommand{\cftchappagefont}{\normalfont} %Unbold chapter page numbers in table of contents
\renewcommand{\cftfigpresnum}{Figure~} %Precede number with "Figure"
\renewcommand{\cftfignumwidth}{2cm} %Add space between figure number and caption
\renewcommand{\cfttabpresnum}{Table~} %Precede number with "Table"
\renewcommand{\cfttabnumwidth}{2cm} %Add space between table number and caption
\renewcommand{\cftchapindent}{0in} %Set indents to increase by 0.5 inches per level
\renewcommand{\cftsecindent}{0.5in} %Set indents to increase by 0.5 inches per level
\renewcommand{\cftsubsecindent}{1in} %Set indents to increase by 0.5 inches per level
\renewcommand{\cftsubsubsecindent}{1.5in} %Set indents to increase by 0.5 inches per level
\renewcommand{\cftparaindent}{2in} %Set indents to increase by 0.5 inches per level
\renewcommand{\cftsubparaindent}{2.5in} %Set indents to increase by 0.5 inches per level
\setlength{\cftfigindent}{0pt} % remove indentation from figures in lof
\setlength{\cfttabindent}{0pt} % remove indentation from tables in lot
\setlength{\cftbeforetabskip}{\parskip} %Spacing between list of table entries
\setlength{\cftbeforefigskip}{\parskip} %Spacing between list of figure entries
\makeatletter
\renewcommand\@tocrmarg{0.5in} % Make long titles wrap when they are 0.5 inches away from page numbers
\makeatother
\newcommand*{\noaddvspace}{\renewcommand*{\addvspace}[1]{}}
\addtocontents{lof}{\protect\noaddvspace} %Prevents gap between chapters in List of Figures
\addtocontents{lot}{\protect\noaddvspace} %Prevents gap between chapters in List of Tables
%Chapter Headings
\usepackage{titlesec}
\titleformat{\chapter}[hang] %Make chapter number and title on same line
{\normalfont\normalsize\bfseries}{\chaptertitlename\ \thechapter:}{1em}{} %Adjust title font formatting (normal, bold)
\titlespacing{\chapter}{0pt}{40pt}{12pt} %{increases the left margin}{vertical space before the title}{separation between title and text}
\titlespacing{\part}{0pt}{35pt}{12pt} %{increases the left margin}{vertical space before the title}{separation between title and text}
%Appendix
%\usepackage[titletoc]{appendix}
\usepackage{tocloft}
\usepackage{calc}
\renewcommand{\cftchappresnum}{\chaptername\space}
%\setlength{\cftchapnumwidth}{\widthof{\textbf{Appendix~999~}}}
\setlength{\cftchapnumwidth}{2cm}
\makeatletter
\g@addto@macro\appendix{%
\addtocontents{toc}{%
\protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}%
}%
}
\newcommand*\annex{%
\renewcommand{\appendixname}{Annex}%
\setcounter{chapter}{0}
\addtocontents{toc}{%
\protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}%
}%
}
\usepackage{blindtext}% only for dummy text
%https://tex.stackexchange.com/questions/435684/how-to-include-appendix-names-in-toc
\begin{document}
\setcounter{tocdepth}{6} %Table of contents goes to level 6 headings
\singlespacing
\tableofcontents % Create List of Tables in Latex
\pagenumbering{roman}
\singlespacing
\listoftables % Create List of Tables in Latex
\addcontentsline{toc}{chapter}{List of Tables}
\newpage
\singlespacing
\listoffigures % Create List of Tables in Latex
\addcontentsline{toc}{chapter}{List of Figures}
\newpage
\pagenumbering{arabic}
\doublespacing
\hypertarget{a-really-long-heading-so-i-see-what-happens-when-it-takes-up-more-than-one-line-just-in-case-were-getting-crazy}{%
\chapter{A Really Long Heading so I see what happens when it takes up more than one line just in case we're getting crazy}\label{a-really-long-heading-so-i-see-what-happens-when-it-takes-up-more-than-one-line-just-in-case-were-getting-crazy}}
\hypertarget{results}{%
\section{Results}\label{results}}
\hypertarget{a-really-long-heading-so-i-see-what-happens-when-it-takes-up-more-than-one-line-just-in-case-were-getting-crazy-1}{%
\subsection{A Really Long Heading so I see what happens when it takes up more than one line just in case we're getting crazy}\label{a-really-long-heading-so-i-see-what-happens-when-it-takes-up-more-than-one-line-just-in-case-were-getting-crazy-1}}
\end{document}
答案1
在 github 上得到了一个回复,可以使用和的组合来实现这一点cftXindent
。选择需要一些反复试验才能找到适合每个标题级别的值。\cftXnumwidth
\cftXaftersnumb
\cftXnumwidth
\renewcommand{\cftchapindent}{0.25in} %Set indents to increase by 0.5 inches per level (1)
\renewcommand{\cftchapaftersnumb}{\hspace*{-0.635cm}} %hanging indent for sections that take up more than one line (level 2)
\renewcommand{\cftsecindent}{0.75in} %Set indents to increase by 0.5 inches per level (2)
\renewcommand{\cftsecnumwidth}{1.5cm} %off set hanging indent for long section lines below (level 2)
\renewcommand{\cftsecaftersnumb}{\hspace*{-0.635cm}} %hanging indent for sections that take up more than one line (level 2)
\renewcommand{\cftsubsecindent}{1.25in} %Set indents to increase by 0.5 inches per level (3)
\renewcommand{\cftsubsecnumwidth}{1.7cm} %off set hanging indent for long section lines below (level 3)
\renewcommand{\cftsubsecaftersnumb}{\hspace*{-0.635cm}}%hanging indent for sections that take up more than one line (level 3)
\renewcommand{\cftsubsubsecindent}{1.75in} %Set indents to increase by 0.5 inches per level (4)
\renewcommand{\cftsubsubsecnumwidth}{1.8cm} %off set hanging indent for long section lines below (level 4)
\renewcommand{\cftsubsubsecaftersnumb}{\hspace*{-0.635cm}}%hanging indent for sections that take up more than one line (level4)
\renewcommand{\cftparaindent}{2.25in} %Set indents to increase by 0.5 inches per level (5)
\renewcommand{\cftparanumwidth}{2.1cm} %off set hanging indent for long section lines below (level 5)
\renewcommand{\cftparaaftersnumb}{\hspace*{-0.635cm}}%hanging indent for sections that take up more than one line (level 5)
\renewcommand{\cftsubparaindent}{2.75in} %Set indents to increase by 0.5 inches per level (6)
\renewcommand{\cftsubparanumwidth}{2.4cm} %off set hanging indent for long section lines below (level 6)
\renewcommand{\cftsubparaaftersnumb}{\hspace*{-0.635cm}}%hanging indent for sections that take up more than one line (level 6)
\renewcommand{\cftchappresnum}{\chaptername\space} %Have Toc say "Chapter" followed by number
\setlength{\cftchapnumwidth}{2.5cm} %Space so caption doesn't overlap "Chapter" number in TOC (added 0.5cm to offset hanging indent)