围绕 itemize 环境更改 \parskip

围绕 itemize 环境更改 \parskip

\parskip我希望段落之间 有一个非零值,但避免将其放在“内联”项目周围。

我可以临时更改每个环境,但我的文档中有很多。我也可以重新定义环境itemize并引入\vspace*{-\parskip},但我更喜欢更简洁的方式。\parskip在环境内部进行更改是无用的,因为它只在组内有效。

\documentclass{article}
\begin{document}
\parskip=6pt
Praesent hendrerit velit at magna tempus, at malesuada augue lacinia. Pellentesque at malesuada est, vel varius enim. In egestas massa et finibus ultricies. Donec felis erat, placerat et sodales in, egestas non mi.

% >> parskip here!
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
% >> no parskip here
\begin{itemize}
  \item first
  \item second
\end{itemize}
% >> no parskip here
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

% >> parskip here!
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\end{document}

paralist像和这样的包似乎并enumitem没有解决存在的问题\parskip

答案1

latex在该上下文中\topsep用作本地版本,因此只需设置为您需要的任何内容,但是如果在不使用 enumitem 或类似包的情况下进行设置,则需要间接设置它,因为文章使用一组预定义的参数设置每个第一级列表。\parskip\parsep

\documentclass{article}
\setlength\parskip{6pt}

\makeatletter
\def\@listI{\leftmargin\leftmargini
            \parsep 4\p@ \@plus2\p@ \@minus\p@
%            \topsep 8\p@ \@plus2\p@ \@minus4\p@
            \topsep\z@
            \itemsep4\p@ \@plus2\p@ \@minus\p@}
\makeatother
\begin{document}

Praesent hendrerit velit at magna tempus, at malesuada augue lacinia. Pellentesque at malesuada est, vel varius enim. In egestas massa et finibus ultricies. Donec felis erat, placerat et sodales in, egestas non mi.

% >> parskip here!
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
% >> no parskip here
\begin{itemize}
  \item first
  \item second
\end{itemize}
% >> no parskip here
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

% >> parskip here!
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\end{document}

或者你可能想要

            \topsep-6pt

取决于你想要的间距有多紧。

答案2

您还可以使用以下命令轻松完成此操作enumitem

\documentclass{article}
\usepackage{enumitem} %
\newlength\docparskip
\parskip=6pt
\setlength{\docparskip}{\parskip}
\setlist{nosep, itemsep=0pt, parsep=0pt, before={\parskip=0pt}, after=\vspace{-\docparskip}}%
\begin{document}
Praesent hendrerit velit at magna tempus, at malesuada augue lacinia. Pellentesque at malesuada est, vel varius enim. In egestas massa et finibus ultricies. Donec felis erat, placerat et sodales in, egestas non mi.

% >> parskip here!
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
% >> no parskip here
\begin{itemize}
  \item first
  \item second
\end{itemize}
% >> no parskip here
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

% >> parskip here!
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\end{document} 

在此处输入图片描述

相关内容