我正在使用解决方案@egreg 提供的背景用于在我的章节标题周围添加背景。但是,目录顶部出现了一个蓝色矩形。有人知道如何删除它吗?
我的目录图片:
一个工作示例:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\usepackage[T1]{fontenc}
\usepackage[left=18mm, right=18mm,top=18mm,bottom=18mm,includehead=true]{geometry}
\usepackage{titlesec}
\usepackage[pdfview=FitB,hidelinks]{hyperref}
%Format the section titles/headings
\titleformat{name=\section,numberless}[hang]
{\Large}
{}
{0pt}
{\colorsection}
\titlespacing*{\section}{-5mm}{\baselineskip}{\baselineskip}
\newcommand{\colorsection}[1]{%
\colorbox{blue!20}{\parbox{\dimexpr\textwidth-2\fboxsep}{#1}}}
\setcounter{secnumdepth}{0} %removes numbering from sections
\title{A TOC with a blue rectangle}
\date{}
\begin{document}
\fontfamily{bch}\selectfont
\maketitle
\def\contentsname{\empty}
\tableofcontents
\clearpage
\section{Why?}
\subsection{O Why?}
\begin{itemize}
\item I don't know.
\end{itemize}
\subsection{Is this rectangle at the top of my TOC?}
The solution is probably very straightforward, but I am just not seeing it.
\section{I'm stumped!}
This is so weird.
\end{document}
答案1
\tableofcontents
问题\section*{\contentsname}
,所以仅仅说是不够的\def\contentsname{\empty}
,顺便说一句,应该
\renewcommand{\contentsname}{}
因为\empty
是不是空。您真正想要做的是\tableofcontents
不发出\section
命令。
对于article
类来说,删除\section
命令的最简单方法是在序言中执行,
\makeatletter
\renewcommand{\tableofcontents}{\@starttoc{toc}}
\makeatother