标题说明了一切。
\documentclass[twoside]{article}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{amssymb,amsmath}
\usepackage{mathrsfs}
\usepackage{titling}
\usepackage{bigints}
\usepackage{mathtools}
\usepackage{centernot}
\usepackage{textcomp}
\usepackage[hidelinks]{hyperref}
\usepackage{fancyhdr}
\fancypagestyle{mypagestyle}{%
\fancyhf{}
\fancyhead[OR]{\thepage}
\fancyhead[EL]{\thepage}
\fancyhead[OC]{\textsc{Jonathan W. Tooker}}
\fancyhead[EC]{\textsc{Levels of Aleph}}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{mypagestyle}
\usepackage{titlesec}
\titleformat{\section}[block]{\Large\bfseries\filcenter}{\S \thesection.} {1em}{} \titleformat{\subsection}[block]{\large\bfseries\filcenter}{\S \thesubsection.}{1em}{}
答案1
您可以使用titletoc
与 (同一作者) 完美交互的包轻松完成此titlesec
操作。要在目录中的每个部分前添加一些垂直空间,我们标记第一个部分并添加\vspace{.5\baselineskip}
部分标题的“before”代码。将此值更改为您需要的任何值。
\documentclass{article}
\usepackage{titlesec}
\usepackage{titletoc}
\newif\iffirst\firsttrue % to flag first TOC entry
\titleformat{\section}[block]{\Large\bfseries\filcenter}{\S \thesection.} {1em}{}
\titleformat{\subsection}[block]{\large\bfseries\filcenter}{\S \thesubsection.}{1em}{}
\titlecontents{section}
[0em]
{\iffirst\global\firstfalse\else\vspace{.5\baselineskip}\fi\bfseries}
{}
{\hspace*{-2.3em}}
{\hfill\contentspage}
\begin{document}
\tableofcontents
\section{A section}
\subsection{A subsection}
\subsection{Another subsection}
\subsection{Another one}
\section{A second section}
\subsection{A subsection}
\end{document}
答案2
您还可以使用包tocbasic
:
\documentclass{article}
\usepackage{titlesec}
\titleformat{\section}[block]{\Large\bfseries\filcenter}{\S \thesection.} {1em}{}
\titleformat{\subsection}[block]{\large\bfseries\filcenter}{\S \thesubsection.}{1em}{}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[
numwidth=0pt,
entrynumberformat=\gobble
]{tocline}{section}
\newcommand\gobble[1]{}
\begin{document}
\tableofcontents
\section{A section}
\subsection{A subsection}
\subsection{Another subsection}
\subsection{Another one}
\section{A second section}
\subsection{A subsection}
\end{document}