包装 parskip 以添加更多(或删除)垂直空间

包装 parskip 以添加更多(或删除)垂直空间

如果您希望段落之间有垂直空间且没有缩进,那么正如我所见,最好的解决方案是使用 parskip 包。但在文档中,该包没有选项,那么如果您想增加或减少垂直空间,该如何更改垂直空间?

答案1

这里,我将parskip.sty,重命名为 ,myparskip.sty并做以下更改:

1)改为\ProvidesPackage{myparskip}

2)改变

\parskip=0.5\baselineskip \advance\parskip by 0pt plus 2pt

\ifdim\parskip>0pt\relax
  \advance\parskip by 0pt plus 2pt
\else
  \parskip=0.5\baselineskip \advance\parskip by 0pt plus 2pt
\fi

如果使用 的零值调用,则会产生效果\parskip,它会模仿parskip包会执行的操作(即设置\parskip为 的值0.5\baselineskip)。另一方面,如果\parskip在调用包之前将 指定为非零值,它将把它作为新的默认值并执行包会执行的其他操作parskip,例如将粘合添加到尺寸\parskip,并调整与列表制作相关的垂直尺寸。

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{myparskip}

\ifdim\parskip>0pt\relax
  \advance\parskip by 0pt plus 2pt
\else
  \parskip=0.5\baselineskip \advance\parskip by 0pt plus 2pt
\fi
\parindent=\z@

%
% from a suggestion by Donald Arseneau on comp.text.tex:

\DeclareOption{parfill}{\setlength{\parfillskip}{30\p@ \@plus 1fil}}
\ProcessOptions

% To accompany this, the vertical spacing in the list environments is changed
% to use the same as \parskip in all relevant places (for normalsize only):
%   \parsep = \parskip
%   \itemsep = \z@ % add nothing to \parskip between items
%   \topsep = \z@ % add nothing to \parskip before first item

\def\@listI{\leftmargin\leftmargini
   \topsep\z@ \parsep\parskip \itemsep\z@}
\let\@listi\@listI
\@listi

\def\@listii{\leftmargin\leftmarginii
   \labelwidth\leftmarginii\advance\labelwidth-\labelsep
   \topsep\z@ \parsep\parskip \itemsep\z@}

\def\@listiii{\leftmargin\leftmarginiii
    \labelwidth\leftmarginiii\advance\labelwidth-\labelsep
    \topsep\z@ \parsep\parskip \itemsep\z@}

% and, now...
%   \partopsep = \z@ % don't even add anything before first item (beyond 
%                    % \parskip) even if the list is preceded by a blank line
\partopsep=\z@

% Note that listiv, listv and listvi don't change vertical parameters.

% deal with a problem raised on comp.text.tex in april 2001
%
% don't expand the table of contents any further
%
% first: check that the definition of \@starttoc is unchanged from
% that in latex.ltx
\@ifundefined{CheckCommand}{}{%
  \CheckCommand*{\@starttoc}[1]{%
    \begingroup
      \makeatletter
      \@input{\jobname.#1}%
      \if@filesw
        \expandafter\newwrite\csname tf@#1\endcsname
        \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
      \fi
      \@nobreakfalse
    \endgroup}}
%
% now having generated any warning that might help, redefine
\renewcommand*{\@starttoc}[1]{%
  \begingroup
    \makeatletter
    \parskip\z@
    \@input{\jobname.#1}%
    \if@filesw
      \expandafter\newwrite\csname tf@#1\endcsname
      \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
    \fi
    \@nobreakfalse
  \endgroup
}

\endinput

考虑这个 MWE,它给出了默认的parskip包行为:

\documentclass{article}
\usepackage{lipsum}
%\parskip\baselineskip
\usepackage{myparskip}
\begin{document}
\lipsum[1]
\begin{itemize}
\item the first
\item the second
\item the third
\end{itemize}
\lipsum[2-6]
\end{document}

在此处输入图片描述

当预先设置该\parskip值(取消注释序言中的一行)时,它会影响段落和列表制作间距:

在此处输入图片描述

答案2

做就是了

\usepackage{parskip}

\setlength{\parskip}{0.75\baselineskip plus 2pt}

这将覆盖默认值0.5\baselineskip plus 2pt


如果你想要打包版本,请将以下内容保存为oparskip.sty

\ProvidesPackage{oparskip}[2016/05/02]

\DeclareOption{parfill}{\PassOptionsToPackage{parfill}{parskip}}
\DeclareOption*{\edef\oparskip@factor{\CurrentOption}}

\ExecuteOptions{0.5} % default

\ProcessOptions\relax

\RequirePackage{parskip}

\setlength{\parskip}{\oparskip@factor\baselineskip plus 2pt}

\endinput

然后你可以打电话

\documentclass{article}
\usepackage[0.75]{oparskip}

\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{itemize}
\item the first
\item the second
\item the third
\end{itemize}
\lipsum[2-6]

\end{document}

如果你想要\usepackage[parfill]{parskip}修改后的因子的等价物,请调用

\usepackage[0.75,parfill]{oparskip}

答案3

从今天起,修订后的 parskip 包想要在选项中指定的跳过值,如下所示:

\usepackage[skip=0.75\baselineskip plus 2pt]{parskip}

正如 Frank 在文档中所说,它并不完美。我注意到,当页面包含测试主体中没有的元素(例如表格、方程式和脚注)时,页面会挤压。

相关内容