我已经在使用 tocloft 包。我有几个很长的章节名称,它们会换行到第二行,但它会与下面的章节编号对齐。我必须让这个新行与原始章节名称对齐。我见过另一个类似的问题,但没有得到回答。示例:
CHAPTER 1: THIS IS AN EXTREMELY LONG,
LONG CHAPTER NAME.......................2
1.1 blah blah...........................3
1.2 blah blah...........................4
I need it to be:
CHAPTER 1: THIS IS AN EXTREMELY LONG,
LONG CHAPTER NAME...............2
1.1 blah blah...........................3
1.2 blah blah...........................4
希望有人可以帮忙!
提前致谢!
注意:其他人编写了我用于论文的类文件,因此我尝试对其进行编辑以满足我所在大学的格式要求。
以下是用于生成目录的原始代码:
% TABLE OF CONTENTS ----------------------------------------------------------
\renewcommand{\cftbeforechapskip}{\baselineskip} % allow spacing after each chapter/section entry
\renewcommand{\contentsname}{TABLE OF CONTENTS}
\renewcommand{\cftbeforetoctitleskip}{-0.25in} % Title is 1in from top
\renewcommand{\cftaftertoctitleskip}{2.0\baselineskip}% 1 double space after title
\renewcommand{\cfttoctitlefont}{\hfill} % Blank space before title
\renewcommand{\cftaftertoctitle}{\hfill} % Blank space after title
\renewcommand{\cftchapfont}{ } % Can make it bold faced here
\renewcommand{\cftchapleader}{\cftdotfill{\cftchapdotsep}}
\renewcommand{\cftchapdotsep}{\cftdotsep} % Puts dots after chapter entries
\renewcommand{\cftchappresnum}{CHAPTER } %
\renewcommand{\cftchapaftersnum}{ } %
\renewcommand{\cftchapaftersnumb}{\phantom{CHAPTER}\rm} %
\renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}%
\renewcommand{\cftchappagefont}{ } %
编译正常,没有错误......当我替换行
\renewcommand{\cftchappresnum}{CHAPTER } %
with
\renewcommand{\cftchappresnum}{CHAPTER\ } %
根据建议,并添加行
\renewcommand{\cftchapnumwidth}{1in}
我在 .toc 文件中发现 9 个错误。
更新:使用修复了 .toc 文件中的 9 个错误
\setlength{\cftchapnumwidth}{1.2in}
代替
\renewcommand{\cftchapnumwidth}{1in}.
我正在研究的最后一件事是这些修复如何与附录补丁兼容:
\newcommand*\tocappendixpatch{%
\addtocontents{toc}{\setcounter{tocdepth}{0}}
\addtocontents{toc}{\protect\renewcommand*\protect\cftchappresnum{\@chapapp\ }}
\addtocontents{toc}{\settowidth{\cftchapnumwidth}{\hspace*{9mm}}}
\renewcommand{\thesection}%
{\Alph{chapter}.\arabic{section}\hspace{-.5em}\setcounter{equation}{0}}
}
目录的其余部分看起来很棒,但我认为附录补丁中的代码有冲突,所以我现在正在努力解决这个问题。
更新:我明白了!我替换了
\addtocontents{toc}{\settowidth{\cftchapnumwidth}{\hspace*{9mm}}}
和
\setlength{\cftchapnumwidth}{1.2in}
在附录补丁中,间距完美匹配,与上面的行相匹配。
这真是太让人紧张了。花了我整个周末的时间!如果只是缩短章节名称就简单多了!!
感谢所有帮助过我的人!!我希望以后有时间的时候能帮助大家解答问题!
答案1
您发布的代码存在许多问题,这可以解释为什么标题不一致。
具体来说:
\renewcommand{\cftchapfont}{ } % this should not have a space
它应该是
\renewcommand{\cftchapfont}{} % notice there is no space here
以下命令:
\renewcommand{\cftchapaftersnumb}{\phantom{CHAPTER}\rm}
是一种间距调整方法。应将其全部删除。
另一个额外的空间是:
\renewcommand{\cftchappagefont}{ } % this should not have a space either
应该
\renewcommand{\cftchappagefont}{}
您可以指定章节号的宽度,文本将适当换行。因此,将命令添加到最小文档中,您将获得以下内容:
\documentclass{book}
\usepackage{tocloft}
\begin{document}
\renewcommand{\cftbeforechapskip}{\baselineskip} % allow spacing after each chapter/section entry
\renewcommand{\contentsname}{TABLE OF CONTENTS}
\renewcommand{\cftbeforetoctitleskip}{-0.25in} % Title is 1in from top
\renewcommand{\cftaftertoctitleskip}{2.0\baselineskip}% 1 double space after title
\renewcommand{\cfttoctitlefont}{\hfill} % Blank space before title
\renewcommand{\cftaftertoctitle}{\hfill} % Blank space after title
\renewcommand{\cftchapfont}{} % Can make it bold faced here; don't put a space in the {}
\renewcommand{\cftchapleader}{\cftdotfill{\cftchapdotsep}}
\renewcommand{\cftchapdotsep}{\cftdotsep} % Puts dots after chapter entries
\renewcommand{\cftchappresnum}{CHAPTER\ } %
\renewcommand{\cftchapaftersnum}{} % Don't put a space in the {}
\renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}%
\renewcommand{\cftchappagefont}{} %
\renewcommand{\cftchapnumwidth}{1in}
\frontmatter
\tableofcontents
\mainmatter
\chapter{A really long chapter heading that will wrap around in the table of contents}
\section{First section}
\section{Second section}
\chapter{Another chapter}
\section{Another section}
\end{document}
答案2
另一个解决方案是使用 Jean-François Burnol 的 etoc 包(参见 etoc 手册第 75 页的示例)。
\documentclass{book}
\usepackage{etoc}
\begin{document}
% From example p.75 The etoc package Jean-François Burnol v1.08g (2015/08/29)
\parindent 0pt \leftskip 0cm \rightskip .75cm \parfillskip -\rightskip
\newcommand*{\EndParWithPagenoInMargin}
{\nobreak\hfill
\nobreak\makebox[0.75cm][r]{\mdseries\normalsize\etocpage}%
\par}
\renewcommand*\etoctoclineleaders
{\hbox{\normalfont\normalsize\hbox to .75ex {\hss.\hss}}}
\newcommand*{\EndParWithPagenoInMarginAndLeaders}
{\nobreak\leaders\etoctoclineleaders\hfill
\nobreak\makebox[0.75cm][r]{\mdseries\normalsize\etocpage}%
\par }
\etocsetstyle {chapter}
{}
{\leavevmode\leftskip 1cm\relax}
{\large\llap{\makebox[1cm][r]{\bfseries Chapter~\etocnumber\ \ }}%
\etocname\EndParWithPagenoInMargin\smallskip}
{}
\etocsetstyle {section}
{}
{\leavevmode\leftskip 0.5cm\relax}
{\normalsize\llap{\makebox[.75cm][l]{\bfseries\etocnumber}}%
\etocname\EndParWithPagenoInMarginAndLeaders}
{}
\tableofcontents
\chapter{A really long chapter heading that will wrap around in the table of contents}
\section{First section}
\section{Second section}
\chapter{A really long chapter heading that will wrap around in the table of contents}
\section{First section}
\section{Second section}
\end{document}