标题周围间距统一,特殊情况为 `\usepackage{enumitem}' 和 `\baselineskip`

标题周围间距统一,特殊情况为 `\usepackage{enumitem}' 和 `\baselineskip`

这个问题是我的问题@karlkoeller回答完全回答了我的问题。但是在我的文档中,有些地方将逐项列表直接放在后面\subsection。这导致小节周围的间距不一致。我想将小节周围的间距匹配蜜蜂的膝盖标题,以便其他\subsection设置相同的间距。下面是我的问题和 MWE 的说明。

新的不均匀性

\documentclass{article}

% insert vertical space between paragraphs
\setlength{\parskip}{\baselineskip} 

% Modifies itemized lists with enumitem http://www.ctan.org/pkg/enumitem
\usepackage{enumitem}
\setlist[itemize]{noitemsep, topsep=0pt, before={\vspace*{-\baselineskip}}} 

 % http://tug.ctan.org/tex-archive/macros/latex/contrib/blindtext/blindtext.pdf
\usepackage{blindtext} 

\begin{document}

\section*{\centering{New ununiformness}}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ornare diam vitae nisl pharetra, quis tincidunt augue finibus. Etiam dignissim lectus eu odio viverra tincidunt. Nulla ultricies finibus magna, et rutrum nisi volutpat quis. Praesent eget eros sapien. 

\noindent
This is the things cancel each other out:
\begin{itemize}
\item dummy first item
\item insert vertical space between paragraphs
\item \verb|[topsep=0pt]| in \verb| \usepackage{enumitem} |
\item dummy last item
\end{itemize}

\subsection*{\centering{Not too funky situation in my actual document}}

Nulla ultricies finibus magna, et rutrum nisi volutpat quis. Praesent eget eros sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ornare diam vitae nisl pharetra, quis tincidunt augue finibus. Etiam dignissim lectus eu odio viverra tincidunt. 

\subsection*{\centering{The Bee's Knees}}
% spacing I like and would like to copy to my other \subsection
\begin{itemize}
\item dummy first item, that is a bit longer to illustrate how close to the subsection heading compared to above.
\item dummy last item
\end{itemize}

\subsection*{\centering{Random Randomness}}

Aliquam ornare diam vitae nisl pharetra, quis tincidunt augue finibus. Etiam dignissim lectus eu odio viverra tincidunt. Nulla ultricies finibus magna, et rutrum nisi volutpat quis. Praesent eget eros sapien. 

\end{document}

答案1

首先,要获得居中的标题,不要做以下事情

\subsection*{\centering{Not too funky situation in my actual document}}

但加载包sectsty并发出

\allsectionsfont{\centering}

然后,为了实现你想要的,首先,改变你\setlist

\setlist[itemize]{noitemsep, topsep=0pt, before={\ifdim\lastskip>0pt\vspace*{-\baselineskip}\fi}}

加载包titlesec并定义

\titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{-1ex plus .2ex}

梅威瑟:

\documentclass{article}

% insert vertical space between paragraphs
\setlength{\parskip}{\baselineskip}

% Modifies itemized lists with enumitem http://www.ctan.org/pkg/enumitem
\usepackage{enumitem}
\setlist[itemize]{noitemsep, topsep=0pt, before={\ifdim\lastskip>0pt\vspace*{-\baselineskip}\fi}}

\usepackage{sectsty}
\allsectionsfont{\centering}

\usepackage{titlesec}
\titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{-1ex plus .2ex}

\begin{document}

\section*{New ununiformness}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ornare diam vitae nisl pharetra, quis tincidunt augue finibus. Etiam dignissim lectus eu odio viverra tincidunt. Nulla ultricies finibus magna, et rutrum nisi volutpat quis. Praesent eget eros sapien.

\noindent
This is the things cancel each other out:
\begin{itemize}
\item dummy first item
\item insert vertical space between paragraphs
\item \verb|[topsep=0pt]| in \verb| \usepackage{enumitem} |
\item dummy last item
\end{itemize}

\subsection*{Not too funky situation in my actual document}

Nulla ultricies finibus magna, et rutrum nisi volutpat quis. Praesent eget eros sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ornare diam vitae nisl pharetra, quis tincidunt augue finibus. Etiam dignissim lectus eu odio viverra tincidunt.

\subsection*{The Bee's Knees}
% spacing I like and would like to copy to my other \subsection
\begin{itemize}
\item dummy first item, that is a bit longer to illustrate how close to the subsection heading compared to above.
\item dummy last item
\end{itemize}

\subsection*{Random Randomness}

Aliquam ornare diam vitae nisl pharetra, quis tincidunt augue finibus. Etiam dignissim lectus eu odio viverra tincidunt. Nulla ultricies finibus magna, et rutrum nisi volutpat quis. Praesent eget eros sapien.

\end{document} 

输出:

在此处输入图片描述

相关内容