为什么我的目录顶部有这么大的空隙?

为什么我的目录顶部有这么大的空隙?

在此处输入图片描述

我尝试删除所有几何图形,删除 usepackage{geometry} 和所有边距以及所有内容,但最终目录仍然离我的顶部很远。我希望它距离顶部 50 毫米。我已将其打印出来并测量。它是 85 毫米。

甚至我的图表、表格、清单都是 85 毫米……

\documentclass[12pt, a4paper, oneside]{report}
\usepackage[T1]{fontenc}
\usepackage{mathptmx} %times font
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{enumerate}
\usepackage{hyperref}
\usepackage{setspace}
\usepackage[english]{babel} %roman & arabic label page
\usepackage[top=50mm, bottom=50mm, left=45mm, right=45mm]{geometry}
%\usepackage{tocbibind} %for hyperref
\usepackage{indentfirst}
\usepackage{apacite} %cite apa
\usepackage{array} %for table width
\usepackage{listings} %codes
\usepackage{caption} % code caption
\usepackage{color} % code caption
\usepackage{xcolor} %code caption
\usepackage{titlesec} % set section/subsection fontstyle & fontsize

\titleformat{\section}
{\normalfont\fontsize{14}{14}\bfseries\itshape}{\thesection}{1em}{}

\titleformat{\subsection}
{\normalfont\fontsize{12}{12}\bfseries\itshape}{\thesubsection}{1em}{}


\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}}

\hypersetup{
colorlinks=true, %set true if you want colored links
linktoc=all,     %set to all if you want both sections and subsections     linked
linkcolor = black,  %choose some color if you want links to stand out
urlcolor=blue, % for \url
citecolor=black, 
}

\pagenumbering{Roman}

\begin{document}
\input{CoverPage}
\thispagestyle{empty}
\cleardoublepage

\input{TitlePage}
\thispagestyle{empty}
\cleardoublepage


\phantomsection
\addcontentsline{toc}{chapter}{Copyright}
\input{CopyrightPage}
\setcounter{page}{1}
\cleardoublepage


\phantomsection
\addcontentsline{toc}{chapter}{Declaration}
\input{DeclarationPage}
\cleardoublepage


\phantomsection
\addcontentsline{toc}{chapter}{Acknowledgement}
\input{AcknowledgementPage}
\cleardoublepage

\phantomsection
\addcontentsline{toc}{chapter}{Management Summary}
\input{ManagementSummaryPage}
\cleardoublepage

\phantomsection
\addcontentsline{toc}{chapter}{Table of Contents}
\renewcommand\contentsname{Table of Contents}
\tableofcontents
\cleardoublepage

\phantomsection
\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures
\cleardoublepage

\phantomsection
\addcontentsline{toc}{chapter}{List of Tables}
\listoftables
\cleardoublepage

\phantomsection
\addcontentsline{toc}{chapter}{List of Algorithms}
\renewcommand\lstlistlistingname{List of Algorithms}
\lstlistoflistings
\cleardoublepage

% % (1) =========================================

\pagenumbering{arabic}
\phantomsection
\addcontentsline{toc}{chapter}{Chapter 1 : Introduction}
\setcounter{chapter}{1}
\input{Chapter1}
\cleardoublepage

\phantomsection
\addcontentsline{toc}{chapter}{Chapter 2 : Background Study }
\setcounter{chapter}{2}
\input{Chapter2}
\cleardoublepage

\phantomsection
\addcontentsline{toc}{chapter}{Chapter 3 : Requirements \& Design}
\setcounter{chapter}{3}
\input{Chapter3}
\cleardoublepage

\phantomsection
\addcontentsline{toc}{chapter}{Chapter 4 : Implementation Plan}
\setcounter{chapter}{4}
\input{Chapter4}
\cleardoublepage

\phantomsection
\addcontentsline{toc}{chapter}{Chapter 5 : Conclusion}
\setcounter{chapter}{5}
\input{Chapter5}
\cleardoublepage

\phantomsection
%\addcontentsline{toc}{chapter}{Reference}
\setcounter{chapter}{6}
\input{References}
\cleardoublepage

\phantomsection
\addcontentsline{toc}{chapter}{Appendix}
\setcounter{chapter}{7}
\input{Appendix}
\cleardoublepage


\end{document}

答案1

您想要的是:修改章节标题周围的间距。例如,可以使用以下包来完成titlesec

\usepackage{titlesec}
\titleformat{\chapter}[display]{\normalfont\huge\bfseries}%
  {\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*\chapter{0pt}{10pt}{40pt}

您可以摆弄这些值10pt40pt根据自己的喜好来微调间距。


需要说的是,我对您的代码还有更多评论:

  • 我不明白为什么chapter每次都要设置计数器,为什么还要手动使用\phantomsection\addcontentsline这似乎是对系统的严重滥用,事情肯定应该以另一种方式完成。

  • 注意,如果您希望章节从奇数页开始,则不能使用[oneside],而必须添加[openright]reportbook类设置[twoside,openright]为默认。

  • 您最好使用包,而不是在目录中手动添加 ToC、LoT 等{tocbibind}

  • hyperref应在大多数其他包之后加载。color如果加载,则不需要xcolor

  • 最好不要使用显式\fontsize{}{}命令,而要依赖标准命令;12pt\normalsize用于您的设置,并且14pt\large。如果您决定使用\fontsize,则第二个数字应该大约 20%,因此\fontsize{12}{14}\fontsize{14.4}{17}会更好。

最后,你的代码可能看起来像这样:

\documentclass[12pt, a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage{mathptmx} %times font
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{enumerate}
\usepackage{setspace}
\usepackage[english]{babel} %roman & arabic label page
\usepackage[top=50mm, bottom=50mm, left=45mm, right=45mm]{geometry}
\usepackage{tocbibind} %for hyperref
\usepackage{indentfirst}
\usepackage{apacite} %cite apa
\usepackage{array} %for table width
\usepackage{listings} %codes
\usepackage{caption} % code caption
\usepackage{xcolor} % code caption

\usepackage{blindtext} % to provide some dummy text

\usepackage{titlesec}

\titleformat{\chapter}[display]{\normalfont\huge\bfseries}%
  {\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*\chapter{0pt}{10pt}{40pt}

\titleformat{\section}
{\normalfont\large\bfseries\itshape}{\thesection}{1em}{}

\titleformat{\subsection}
{\normalfont\normalsize\bfseries\itshape}{\thesubsection}{1em}{}

\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}}

\usepackage{hyperref}

\hypersetup{
colorlinks=true, %set true if you want colored links
linktoc=all,     %set to all if you want both sections and subsections     linked
linkcolor = black,  %choose some color if you want links to stand out
urlcolor=blue, % for \url
citecolor=black, 
}

\begin{document}

% FRONTMATTER

\pagenumbering{Roman}

\renewcommand\contentsname{Table of Contents}
\tableofcontents

\listoffigures

\listoftables

\renewcommand\lstlistlistingname{List of Algorithms}
\lstlistoflistings

% MAINMATTER

\cleardoublepage
\pagenumbering{arabic}

\chapter{First Chapter}
\Blindtext


\chapter{Second Chapter}
\Blindtext


\end{document}

相关内容