我使用该parskip
包有两个原因:
- 在段落之间添加空格。
- 删除段落第一行的缩进。
但是,这个包使得小节标题前后的间距变得非常宽。我尝试使用包\titlespacing
中的宏titlesec
来修改该空格,但似乎其他包排除了这个。它没有任何效果。
我怎样才能减少该空间?
答案1
按照我的评论的建议(利用我的回答章节标题前后的间距),但将结果应用于小节,并减少间距。
编辑以采纳 Gustavo 的建议:1)实现可选参数\subsection
;2)用作-\parskip
调整后的垂直高度。
\documentclass{article}
\usepackage{parskip}
\begin{document}
\tableofcontents
\noindent\hrulefill
\section{Without Fix}
Blah blah
\subsection{First subsection}
This is the first line of text. Note the vertical spacing.
\subsection{Second subsection}
Observe the spacing prior to and following the subsectioning command. Now let me
redefine a few things.
\makeatletter
\let\origsubsection\subsection
\renewcommand\subsection{\@ifstar{\starsubsection}{\nostarsubsection}}
\newcommand\nostarsubsection[2][\relax]{%
\subsectionprelude%
\ifx\relax#1\origsubsection{#2}\else\origsubsection[#1]{#2}\fi%
\subsectionpostlude}
\newcommand\starsubsection[2][\relax]{%
\subsectionprelude%
\ifx\relax#1\origsubsection*{#2}\else\origsubsection*[#1]{#2}\fi%
\subsectionpostlude}
\newcommand\subsectionprelude{%
\vspace{-\parskip}% OR ANY OTHER DESIRED VALUE
}
\newcommand\subsectionpostlude{%
\vspace{-\parskip}% OR ANY OTHER DESIRED VALUE
}
\makeatother
\section{With Fix}
Blah blah
\subsection[Alternate TOC title]{Next subsection}
Did this text raise parskip higher relative to the heading than the prior
subsection? If so, we have succeeded.
\subsection*{Non-numbered subsection}
Here is some text.
\subsection{Final subsection}
And the result is permananent, as you can see.
\end{document}
答案2
由于我无法理解的原因,史蒂文拒绝了我使用的建议xparse
。不过,我认为这样的答案可能会引起人们的兴趣,所以我自己提供了答案。
我赞同史蒂文的做法,即不对\subsection
实施方式做任何假设:
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\usepackage{parskip}
\usepackage{xparse}
\let \originalSubsection \subsection
\RenewDocumentCommand \subsection { s o m } {%
\vspace{-\parskip}%
\IfBooleanTF{#1}{%
\originalSubsection*{#3}%
}{%
\IfValueTF{#2}{%
\originalSubsection[#2]{#3}%
}{%
\originalSubsection{#3}%
}%
}%
\vspace{-\parskip}%
}
\begin{document}
\tableofcontents
\section{With Fix}
Blah blah.
\subsection*{A starred subsection}
This subsection has no number, and is not included in the ToC\@.
\subsection{Normal subsection}
This subsection is normal in all respects: it is numbered, and appears in the
ToC\@ with the same title as above.
\subsection[Short title]{A somewhat longer title}
Numbered subsection, but with a different title in the ToC\@.
\subsection*[Ignored argument]{This is possible too\ldots}
\ldots and it is a well-known issue; it doesn't hurt, anyway!
\end{document}