请问如何调整目录页大标题”目录”两字与上方页眉、下方检索标题之间的间距?

发布于 2022-02-02 18:33:20

image.png
请问使用\tableofcontents命令时如何更改图中标注的两个间距,谢谢

我目前的代码是

\renewcommand{\tableofcontents}
{
    \ABC@chapter*{目\quad 录}
    \@starttoc{toc}
}
\setcounter{secnumdepth}{3}
% ----------------------------------------------
% 定义各级标题在目录中的格式
% ----------------------------------------------
\titlecontents{chapter}
              [0em]
              {\linespread{1.625} \zihao{-4} \songti}
              {\thecontentslabel \hspace{1em}}%
              {}
              {\titlerule*[0.3pc]{.}\contentspage}
              
\titlecontents{section}
              [2em]
              {\linespread{1.625} \zihao{-4} \songti}
              {\thecontentslabel \hspace{0.5em}}%
              {}
              {\titlerule*[0.3pc]{.}\contentspage}

\titlecontents{subsection}
    [4em]
    {\linespread{1.625} \zihao{-4} \songti} % note that 3.8 = 1.5 + 2.3
    {\thecontentslabel \hspace{0.5em}}
    {}
    {\titlerule*[0.3pc]{.}\contentspage}
% ----------------------------------------------
%一级标题格式设置
% ----------------------------------------------
\ctexset{%
    chapter = {%
        format       = \linespread{1.0} \zihao{3} \heiti \centering,
        name         = {第, 章},
        nameformat   = {},
        number       = \arabic{chapter},
        numberformat = {},
        titleformat  = {},
        aftername    = \quad,
        afterindent  = true,
        fixskip      = true,
        beforeskip   = {11pt},
        afterskip    = {38pt},
    },
}

代码中

\abc@chapter*{目\quad 录}

处看似“目录”两字用的是一级标题形式,但不知为何后面一级标题格式设置没有对它起作用


(2022年2月3日更新)
我在下方回复里添加了目前的进展,通过使用tocloft宏包调整两个间距的目标达到了,但是产生“目 录”中的空格的\quad命令现在却似乎受到tocloft宏包影响不起作用了,请问有谁知道应该如何解决,谢谢

查看更多

关注者
0
被浏览
1.9k
2 个回答
雾月
雾月 2022-02-02
这家伙很懒,什么也没写!

设置 \ctexset{chapter/fixskip=false}

目录名称可以通过 \ctexset{contentsname={...}} 修改,或者重定义 \contentsname,一般不必直接修改 \tableofcontents 命令。

另外,你给的这个问题的代码是不能直接编译的,文档类、\usepackage 部分没有给,最重要的是 \abs@chapter 的定义没有给。

Contour
Contour 2022-02-02
这家伙很懒,什么也没写!

问题得到了部分解决,可以使用tocloft宏包中的cftbeforetoctitleskip和cftaftertoctitleskip命令调整原问题图中的两个间距(刘海洋《LaTeX入门》第三章3.1.3节),但是tocloft会造成额外影响,

\ABC@chapter*{目\quad 录}

中的\quad在输出结果中没有展现空格(如下图),试了几次发现这个问题非常顽固。
image.png
修改后代码如下:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 下面是.cls文件里的内容
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ----------------------------------------------
% 声明部分(Identification)
% 指定模板使用的 Latex 版本,标识输出模板名
% ----------------------------------------------
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{ABCthesis}[2021/01/30]
% ----------------------------------------------
% 读取基类
% ----------------------------------------------
\LoadClass[UTF8,openany,a4paper,oneside,zihao=-4]{ctexbook}
% ----------------------------------------------
% 加载宏包
% ----------------------------------------------
\RequirePackage{ctex}
% 设置目录
\RequirePackage{titletoc}
% 更改目录页大标题“目录”格式
\RequirePackage{tocloft}

% ----------------------------------------------

\newcommand\ABC@pdfbookmark[2]{}
% 定义通用的chapter命令
\NewDocumentCommand{\ABC@chapter}{s m}
{
  \if@openright\cleardoublepage\else\clearpage\fi
  \IfBooleanTF{#1}
  {
      \ABC@pdfbookmark{0}{#2}
  }
  {
      \addcontentsline{toc}{chapter}{#2}
  }
  \chapter*{#2}
}

\renewcommand{\tableofcontents}
{
    \ABC@chapter*{目\quad 录}
    \@starttoc{toc}
}
\renewcommand{\cfttoctitlefont}{\hspace*{\fill} \linespread{1.0} \zihao{3} \heiti}
\renewcommand{\cftaftertoctitle}{\hspace*{\fill}}
%上面两行代码中的\hspace*{\fill}不可删除,否则使用tocloft宏包中\cfttoctitlefont的同时LaTeX 会删除行尾的水平空间,导致大标题“目录”不能居中展示。为了防止这种情况,需要插入一个虚拟文本,如\fill。
\setlength\cftbeforetoctitleskip{9.5pt} %改变目录页大标题“目录”前间距
\setlength\cftaftertoctitleskip{11pt} %改变目录页大标题“目录”后间距
\setcounter{secnumdepth}{3}
% ----------------------------------------------
% 定义各级标题在目录中的格式(没有更改)
% ----------------------------------------------
\titlecontents{chapter}
              [0em]
              {\linespread{1.625} \zihao{-4} \songti}
              {\thecontentslabel \hspace{1em}}%
              {}
              {\titlerule*[0.3pc]{.}\contentspage}
              
\titlecontents{section}
              [2em]
              {\linespread{1.625} \zihao{-4} \songti}
              {\thecontentslabel \hspace{0.5em}}%
              {}
              {\titlerule*[0.3pc]{.}\contentspage}

\titlecontents{subsection}
    [4em]
    {\linespread{1.625} \zihao{-4} \songti} % note that 3.8 = 1.5 + 2.3
    {\thecontentslabel \hspace{0.5em}}
    {}
    {\titlerule*[0.3pc]{.}\contentspage}
% ----------------------------------------------
% 一级标题格式设置(没有更改)
% ----------------------------------------------
\ctexset{%
    chapter = {%
        format       = \linespread{1.0} \zihao{3} \heiti \centering,
        name         = {第, 章},
        nameformat   = {},
        number       = \arabic{chapter},
        numberformat = {},
        titleformat  = {},
        aftername    = \quad,
        afterindent  = true,
        fixskip      = true,
        beforeskip   = {11pt},
        afterskip    = {38pt},
    },
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 下面是main.tex文件里的内容
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ----------------------------------------------
% 载入模版
% ----------------------------------------------
\documentclass[]{ABCthesis}
% ----------------------------------------------
% 正文区
% ----------------------------------------------
\begin{document}

\tableofcontents
\chapter{AcBd一级标题}
\section{二级标题}
\subsection{三级标题}
\subsubsection{四级标题}

\end{document}

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览