我想去掉小节中的点。我还想让各节和小节的目录垂直行距相同。现在,下面的代码打印各节和小节的点,而目录中的小节挤在一起。谢谢!
\documentclass[letterpaper,twoside,notitlepage]{article}
\setcounter{tocdepth}{2}
\usepackage{titletoc}
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
%%%%%%%%%NO SECTION NUMBERS IN TOC%%%%%%%%%%%%%%%%%%%
\makeatletter
\let\latexl@section\l@section
\def\l@section#1#2{\begingroup\let\numberline\@gobble\latexl@section{#1}{#2}\endgroup}
\let\latexl@subsection\l@subsection
\def\l@subsection#1#2{\begingroup\let\numberline\@gobble\latexl@subsection{#1}{#2}\endgroup}
\makeatother
\begin{document}
%%%%%%%%%%%% SET TOC LINE SPACING%%%%%%%%%%%%%%%%
\renewcommand{\baselinestretch}{1}\normalsize
\addtocontents{toc}{\protect\thispagestyle{empty}}
\tableofcontents
\thispagestyle{empty}
\renewcommand{\baselinestretch}{1.5}\normalsize
\newpage
\section{Section 1}
\subsection{Subsection 1}
\subsection{Subsection 2}
\subsection{Subsection 3}
\section{Section 2}
\section{Section 3}
\section{Section 4}
\end{document}
答案1
将其添加到您的序言中应该可以实现您想要的效果:
\setlength{\cftbeforesubsecskip}{1\baselineskip}
\renewcommand{\cftsubsecdotsep}{\cftnodots}
如需了解更多信息,请参阅tocloft 手册第 8 至 12 页。
完整代码:
\documentclass[letterpaper,twoside,notitlepage]{article}
\setcounter{tocdepth}{2}
\usepackage{titletoc}
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
%%%%%%%%%NO SECTION NUMBERS IN TOC%%%%%%%%%%%%%%%%%%%
\makeatletter
\let\latexl@section\l@section
\def\l@section#1#2{\begingroup\let\numberline\@gobble\latexl@section{#1}{#2}\endgroup}
\let\latexl@subsection\l@subsection
\def\l@subsection#1#2{\begingroup\let\numberline\@gobble\latexl@subsection{#1}{#2}\endgroup}
\makeatother
\setlength{\cftbeforesubsecskip}{1\baselineskip}
\renewcommand{\cftsubsecdotsep}{\cftnodots}
\begin{document}
%%%%%%%%%%%% SET TOC LINE SPACING%%%%%%%%%%%%%%%%
\renewcommand{\baselinestretch}{1}\normalsize
\addtocontents{toc}{\protect\thispagestyle{empty}}
\tableofcontents
\thispagestyle{empty}
\renewcommand{\baselinestretch}{1.5}\normalsize
\newpage
\section{Section 1}
\subsection{Subsection 1}
\subsection{Subsection 2}
\subsection{Subsection 3}
\section{Section 2}
\section{Section 3}
\section{Section 4}
\end{document}