如何减少目录中部分标题前的垂直空间?
以下是我所拥有的与标题及其目录条目相关的内容(我认为):
\documentclass{article}
\usepackage{titletoc}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
{\parindent \z@
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >\m@ne
\Large\bfseries\hfil\partname~\thepart\hfil
\par\nobreak
\fi
\huge\bfseries\sffamily\raggedleft #2%
\markboth{}{}\par}%
\nobreak
\vskip 3ex
\@afterheading}
\makeatother
\makeatletter
\@addtoreset{section}{part}
\@addtoreset{subsection}{section}
\@addtoreset{subsubsection}{subsection}
\makeatother
\titlecontents{section}[1.8em]{}{\contentslabel{1.8em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}[4.65em]{}{\contentslabel{2.85em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsubsection}[8.35em]{}{\contentslabel{3.75em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\renewcommand*\thepart{\arabic{part}}
\renewcommand*\thesection{\thepart.\arabic{section}}
\begin{document}
\tableofcontents
\newpage
\part{sxsafawf}
\section{sasrvth}
\part{sxsafawf}
\section{sasrvth}
\end{document}
答案1
我认为您正在谈论的是\part
而不是\chapter
。
由于您正在重新定义\part
命令,因此只需添加以下行
\addtocontents{toc}{\protect\vspace*{-15\p@}}
在重新定义中(-15\p@
根据您的需要进行调整)。
梅威瑟:
\documentclass{article}
\usepackage{titletoc}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{part}%
\addtocontents{toc}{\protect\vspace*{-15\p@}}% <------------ added
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addtocontents{toc}{\protect\vspace*{-15\p@}}% <------------ added
\addcontentsline{toc}{part}{#1}%
\fi
{\parindent \z@
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >\m@ne
\Large\bfseries\hfil\partname~\thepart\hfil
\par\nobreak
\fi
\huge\bfseries\sffamily\raggedleft #2%
\markboth{}{}\par}%
\nobreak
\vskip 3ex
\@afterheading}
\makeatother
\makeatletter
\@addtoreset{section}{part}
\@addtoreset{subsection}{section}
\@addtoreset{subsubsection}{subsection}
\makeatother
\titlecontents{section}[1.8em]{}{\contentslabel{1.8em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}[4.65em]{}{\contentslabel{2.85em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsubsection}[8.35em]{}{\contentslabel{3.75em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\renewcommand*\thepart{\arabic{part}}
\renewcommand*\thesection{\thepart.\arabic{section}}
\begin{document}
\tableofcontents
\newpage
\part{sxsafawf}
\section{sasrvth}
\part{sxsafawf}
\section{sasrvth}
\end{document}
输出:
答案2
如果您不想指定\titlecontents{part}
并且对类的默认排版感到满意article
,那么修补原始\l@part
命令就足够了,该titletoc
命令调用\ttl@savel@part
:
\documentclass{article}
\usepackage{titletoc}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\ttl@savel@part}{2.25em}{1em}{}{} % <--- adjust to suit
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
{\parindent \z@
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >\m@ne
\Large\bfseries\hfil\partname~\thepart\hfil
\par\nobreak
\fi
\huge\bfseries\sffamily\raggedleft #2%
\markboth{}{}\par}%
\nobreak
\vskip 3ex
\@afterheading}
\makeatother
\makeatletter
\@addtoreset{section}{part}
\@addtoreset{subsection}{section}
\@addtoreset{subsubsection}{subsection}
\makeatother
\titlecontents{section}[1.8em]{}{\contentslabel{1.8em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}[4.65em]{}{\contentslabel{2.85em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsubsection}[8.35em]{}{\contentslabel{3.75em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\renewcommand*\thepart{\arabic{part}}
\renewcommand*\thesection{\thepart.\arabic{section}}
\begin{document}
\tableofcontents
\newpage
\part{sxsafawf}
\section{sasrvth}
\part{sxsafawf}
\section{sasrvth}
\end{document}
答案3
重新定义\part
目录中的格式并给出间距参数就足够了。顺便说一下,写作
\@addtoreset{subsection}{section}
\@addtoreset{subsubsection}{subsection}
毫无用处 — — 这是默认设置。
有以下可能性:
\documentclass{article}
\usepackage{titletoc}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
{\parindent \z@
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >\m@ne
\Large\bfseries\hfil\partname~\thepart\hfil
\par\nobreak
\fi
\huge\bfseries\sffamily\raggedleft #2%
\markboth{}{}\par}%
\nobreak
\vskip 3ex
\@afterheading}
\makeatother
\makeatletter
\@addtoreset{section}{part}
\@addtoreset{subsection}{section}
\@addtoreset{subsubsection}{subsection}
\makeatother
\titlecontents{part}[0em]{\vspace{2ex}\bfseries}{\contentslabel{1.8em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}[\smallskip]
\titlecontents{section}[3.6em]{}{\contentslabel{1.8em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}[4.65em]{}{\contentslabel{2.85em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsubsection}[8.35em]{}{\contentslabel{3.75em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\renewcommand*\thepart{\arabic{part}}
\renewcommand*\thesection{\thepart.\arabic{section}}
\begin{document}
\tableofcontents
\newpage
\part{sxsafawf}
\section{sasrvth}
\section{another section}
\section{a third section}
\part{sxsafawf}
\section{sasrvth}
\end{document}