如何防止 TeX 将胶水拉伸至超过给定的最大值?

如何防止 TeX 将胶水拉伸至超过给定的最大值?

是否可以定义一种胶水,使得 TeX 在任何情况下都不会超出给定的限制?

在下面的 MWE 中,我想将一段文本与其他文本分开半行,如果这段文本位于分页符上,则应允许将半行拉伸为一行,以便整个文本保持在基线网格上并填满页面。但是,无论页面是否变满,我都不希望粘连拉伸超过一行。

\documentclass{memoir}

\usepackage{tikz, lipsum, everypage}

% show the baseline grid
\makeatletter
\newcommand{\left@margin}{}
\AddEverypageHook{
    \ifodd\value{page}\relax%
        \renewcommand{\left@margin}{\spinemargin}
    \else
        \renewcommand{\left@margin}{\foremargin}
    \fi
    % + \trimtop because it is also "\trimbottom"
    \tikz[overlay, remember picture, background rectangle/.style={fill=none},
            shift={(current page.south west)},xshift={\left@margin + \trimedge},
            yshift={\lowermargin + \trimtop}]%
    {%
        \draw[red!20!white,thin] (0,0) grid[step=\onelineskip] (\textwidth,
        \textheight);%
        \draw[red,thin] (0,0) rectangle (\textwidth,\textheight);
    }%
}%
\makeatother

\parskip=0pt

\begin{document}

\lipsum*[1-2]

\vskip .5\baselineskip plus .5\baselineskip % HERE should be the .5 limit

This is a test line of text to show my case, and I needed a few words to fill the line.

\vskip .5\baselineskip plus .5\baselineskip % HERE should be the .5 limit

\lipsum*[1-2]  Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis
Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis Morbi auctor
lorem non justo. Nam lacus libero, pretium at, lobortis Nam lacus libero, pretium at,
lobortis Morbi auctor lorem non justo. Nam

\section{Test}

\lipsum*[1]

\end{document}

结果如下:

在此处输入图片描述

可以看到,两行加上前后的空格一共占了5行,而不是4行。

答案1

如果拉伸分量不为零,则胶水将任意拉伸(但劣化程度不断增加),因此如果您想要上限,则正分量必须为零。但是,您可以使用长度

1\baselineskip minus 0.5\baselineskip

它被限制在您指定的有限范围内,但是它的自然长度是上限而不是下限,因此您可能需要“鼓励”它缩小。

或者,您可以使用固定单位,并且不允许拉伸或收缩

\vskip 1\baselineskip
\penalty0
\vskip-0.5\baselineskip

将是半基线跳跃,除非在惩罚处发生分页符,在这种情况下它将是完整的基线跳跃(-0.5\baselineskip在分页符处丢弃胶水)

相关内容