我的主要问题是链接的锚定chapter
:当点击目录中的章节时,锚定会将行放在页面顶部的章节标题下方。这导致无法看到章节标题本身。
任何帮助,将不胜感激
\documentclass[12pt]{report}
\usepackage[dvipsnames]{xcolor}
\usepackage[parfill]{parskip}
\usepackage[margin=1in]{geometry}
\usepackage{listings}
\usepackage{fullpage}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{hyperref}
\hypersetup{
colorlinks,
linkcolor={blue!80!black},
citecolor={blue!50!black},
urlcolor={blue!80!black}
}
%% Spacing
\titlecontents{chapter}[0em]{\smallskip\bfseries}%\vspace{1cm}%
{}%
{\itshape\bfseries}%numberless%
{\hfill\contentspage}%
\titlecontents{section}[4.25em]{\smallskip}%
{\contentslabel[\thecontentslabel]{2em}}%numbered
{\hspace{-1em}}
{\hfill\contentspage}%
%Misc
\lstset{breaklines, numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt}
\titleformat{\chapter}[display]
{\normalfont\bfseries\centering\color{BrickRed}}{}{0pt}{\LARGE}[\titlerule]
\titlespacing{\chapter}{0pt}{-75pt}{\parskip}
\makeatletter
\renewcommand{\@dotsep}{10000}
\makeatother
\renewcommand{\contentsname}{Table of Contents}
\makeatletter
\newcommand\frontmatter{\cleardoublepage\pagenumbering{roman}}
\newcommand\mainmatter{ \cleardoublepage\pagenumbering{arabic}}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\setcounter{chapter}{-1}
\chapter{Introduction}
\chapter{The First Chapter}
\end{document}
答案1
您正在将章节标题发送到标题区域,而链接将转到文本区域。
和\titlespacing{\chapter}{0pt}{-25pt}{\parskip}
\documentclass[12pt]{report}
\usepackage[dvipsnames]{xcolor}
\usepackage[parfill]{parskip}
\usepackage[margin=1in, showframe]{geometry} % show the margins
\usepackage{listings}
%\usepackage{fullpage} % do not use
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{hyperref}
\hypersetup{
colorlinks,
linkcolor={blue!80!black},
citecolor={blue!50!black},
urlcolor={blue!80!black}
}
%% Spacing
\titlecontents{chapter}[0em]{\smallskip\bfseries}%\vspace{1cm}%
{}%
{\itshape\bfseries}%numberless%
{\hfill\contentspage}%
\titlecontents{section}[4.25em]{\smallskip}%
{\contentslabel[\thecontentslabel]{2em}}%numbered
{\hspace{-1em}}
{\hfill\contentspage}%
%Misc
\lstset{breaklines, numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt}
\titleformat{\chapter}[display]
{\normalfont\bfseries\centering\color{BrickRed}}{}{0pt}{\LARGE}[\titlerule]
\titlespacing{\chapter}{0pt}{-25pt}{\parskip} % changed <<<<<<<<<<<<<<<<<<<
\makeatletter
\renewcommand{\@dotsep}{10000}
\makeatother
\renewcommand{\contentsname}{Table of Contents}
\makeatletter
\newcommand\frontmatter{\cleardoublepage\pagenumbering{roman}}
\newcommand\mainmatter{ \cleardoublepage\pagenumbering{arabic}}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\setcounter{chapter}{-1}
\chapter{Introduction}
Some text
\chapter{The First Chapter}
Some text
\end{document}
更新后续问题之后
如果您不需要标题区域,请抑制顶部边距。
\usepackage[top=0in,bottom=1in, left=1in, right= 1in, showframe]{geometry}
并取出包装fullpage
。