我有以下 MWE:
\documentclass{article}
\usepackage{lipsum}
\usepackage{titlesec}
\setcounter{secnumdepth}{5}
\begin{document}
\section{Section}
\lipsum[1]
\subsection{Subsection}
\lipsum[2]
\subsubsection{Subsubection}
\lipsum[3]
\paragraph{Paragraph}
\lipsum[4]
\subparagraph{Subparagraph}
\lipsum[5]
\end{document}
但是,每个章节/段落标题前后都有大量水平空间。小段落也有不必要的缩进。
答案1
包括水平空格(标题数字后)和标题前后的间距,无需使用sectsty
。根据需要更改 \titleformat 中的格式命令以及数字和标题之间的水平间距。
\documentclass{article}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage[T1]{fontenc} % EDIT - allows multiple font styles %
% Change horizontal space in titles here
% [block]{Formatting command}{Put `the' in front of paragraph etc}{Space after number}{}
\titleformat{\section}[block]{\large\scshape\bfseries}{\thesection.}{0.2em}{}
\titleformat{\subsection}[block]{\large\scshape}{\thesubsection}{0.3em}{}
% EDIT - to show the multiple font styles being applied due to package `fontenc`
\titleformat{\subparagraph}[block]{\scshape\bfseries}{\thesubparagraph}{0.3em}{}
% Change vertical space \beforetitle and \aftertitle here, as above use \subparagraph etc.
% 0pt is how far from the left margin the entry is placed
\newcommand\aftertitle{2ex}
\newcommand\beforetitle{0.7ex}
\titlespacing*{\section}{0pt}{\aftertitle}{\beforetitle}
\titlespacing*{\subsection}{0pt}{\aftertitle}{\beforetitle}
\titlespacing*{\subsubsection}{0pt}{\aftertitle}{\beforetitle}
\titlespacing*{\paragraph}{0pt}{\aftertitle}{\beforetitle}
\titlespacing*{\subparagraph}{0pt}{\aftertitle}{\beforetitle}
\setcounter{secnumdepth}{5}
\begin{document}
\section{Section}
\lipsum[1]
\subsection{Subsection}
\lipsum[2]
\subsubsection{Subsubection}
\lipsum[3]
\paragraph{Paragraph}
\lipsum[4]
\subparagraph{Subparagraph}
\lipsum[5]
\end{document}
它的外观(编辑 - 已更新以包含fontenc
用于子段落格式化的包):