答案1
使用该titlesec
包“格式化”目录名称,以摆脱前后的默认空格。
我猜你正在使用书籍或报告类,所以我瞄准了部分命令 \chapter
。
该命令\setupTOC
允许将修复仅应用于目录。
您可能需要根据章节标题的具体设置来修改前后的空格。
\documentclass[12pt,a4paper]{book}
\usepackage{multicol}
\renewcommand*\contentsname{}
%************************************* added
\usepackage{titlesec}
\newcommand*{\setupTOC}{%
\titleformat{\chapter}{}{}{0pt}{}
\titlespacing*{\chapter}{0pt}
{*7} % % vertical space before the title <<<<<<<<<<
{*-15} % idem after title (in ex units + glue) <<<<<<<<<<<
}
%*************************************
\begin{document}
\begin{center}
{\Large \bfseries TABLE OF CONTENTS\bigskip}
\end{center}
\begin{multicols}{2}
{\setupTOC \tableofcontents}
\end{multicols}
\chapter{One}
\section{Section one}
\subsection{Subsection one}
\subsection{Subsection two}
\section{Section two}
\subsection{Subsection one}
\subsection{Subsection two}
\subsection{Subsection three}
\subsection{Subsection four}
\section{Section three}
\section{Section four}
\subsection{Subsection one}
\subsection{Subsection two}
\chapter{Two}
\section{Section one}
\subsection{Subsection one}
\subsection{Subsection two}
\section{Section two}
\subsection{Subsection one}
\subsection{Subsection two}
\subsection{Subsection three}
\subsection{Subsection four}
\section{Section three}
\section{Section four}
\subsection{Subsection one}
\subsection{Subsection two}
\chapter{Three}
\section{Section one}
\subsection{Subsection one}
\subsection{Subsection two}
\section{Section two}
\subsection{Subsection one}
\subsection{Subsection two}
\subsection{Subsection three}
\subsection{Subsection four}
\section{Section three}
\section{Section four}
\subsection{Subsection one}
\subsection{Subsection two}
\end{document}
\end{document}
答案2
请注意,这\tableofcontents
取决于文档类别。这仅适用于文章。
\documentclass{article}
\usepackage{multicol}
\makeatletter
\renewcommand\tableofcontents{%
\section*{\makebox[\linewidth][c]{\contentsname}%
\@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
\begin{multicols}{2}%
\@starttoc{toc}%
\end{multicols}
}
\makeatother
\begin{document}
\tableofcontents
\section{test}
\section{another test}
\end{document}