当一行有数学运算时如何获得相等的垂直间距

当一行有数学运算时如何获得相等的垂直间距

我想让小页面中所有行之间的垂直间距相同。我想让每行的间距尽可能大最大限度。我找到了一些方法来阻止创建额外空间,方法是按照\smash这里建议的方式:

如何在文本中内嵌数学公式时强制使用正常行距

和这里:

排版高数学符号时,如何停止自动行距增加?

但我更喜欢增加其他行,而不是手动进行(例如硬编码一定的长度)。

这可能吗?

下面是我有一个 MWE:

\documentclass{article}
\begin{document}
\begin{minipage}[t]{1\columnwidth}%
Just some normal text before the math. Go on a bit of a bit longer so
that this wraps into a couple of lines. I wish I had a funny joke to
tell you but I cant remember any. For example, 
$\widehat{\Omega_{YOU}^{\hat{XYZ}}}=DYNAMICS$ is a model that I would
like to examine. OK now lets do some more filler text here to see
another line and check out the spacing. If you read this far you
deserve an award.
\end{minipage}
\end{document}

答案1

下面的例子定义了一个宏\MaximizeBaselineskip,把整个文本放在一个水平框中,并测量宽度和高度以获得的上限\baselineskip

\documentclass{article}

\newcommand{\MaximizeBaselineskip}[1]{%
  \sbox0{#1}%
  \baselineskip=\dimexpr\ht0+\dp0\relax
  #1%
}

\begin{document}
\noindent
\begin{minipage}[t]{1\columnwidth}%
\MaximizeBaselineskip{%
Just some normal text before the math. Go on a bit of a bit longer so
that this wraps into a couple of lines. I wish I had a funny joke to
tell you but I cant remember any. For example,
$\widehat{\Omega_{YOU}^{\hat{XYZ}}}=\mathit{DYNAMICS}$
is a model that I would
like to examine. OK now lets do some more filler text here to see
another line and check out the spacing. If you read this far you
deserve an award.}%
\end{minipage}
\end{document}

结果

优化版本

\baselineskip上面找到的 开始,可以测试较小的值。根据先前的框深度,最大值可能不是必需的。以下示例实现了二分搜索以查找较小的值。

\documentclass{article}

\usepackage{environ}

\makeatletter
\newdimen\minmax@baselineskip
\newif\ifminmax@todo@
\NewEnviron{minmaxminipage}{%
  \begingroup
    \toks@=\expandafter{\@parboxrestore}%
    \let\@minmaxminipage@baselineskip\relax
    \minmax@baselineskip=\normalbaselineskip
    \edef\@parboxrestore{%
      \the\toks@
      \lineskiplimit=0pt %
      \lineskip=10in %
      \baselineskip=\minmax@baselineskip\relax
    }%
    \edef\TESTBODY{%
      \noexpand\begin{minmax@test}%
      \unexpanded\expandafter{\BODY}%
      \noexpand\end{minmax@test}%
    }%
    \edef\BODY{%
      \noexpand\begin{minipage}%
      \unexpanded\expandafter{\BODY}%
      \noexpand\end{minipage}%
    }%
    \sbox0{\TESTBODY}%
    \minmax@baselineskip=\dimexpr\ht0+\dp0\relax
    \typeout{* Max: \the\minmax@baselineskip}%
    \edef\minmax@upper{\the\minmax@baselineskip}%
    \def\minmax@lower{0pt}%
    \sbox0{\BODY}%
    \edef\minmax@HT{\the\dimexpr\ht0+\dp0\relax}%
    % \typeout{* Tr0: \the\minmax@baselineskip\space -> \minmax@HT}%
    \minmax@todo@true
    \loop
    \ifminmax@todo@
      \minmax@baselineskip=.5\dimexpr\minmax@upper+\minmax@lower\relax
      \sbox0{\BODY}%
      \edef\minmax@new@HT{\the\dimexpr\ht0+\dp0\relax}%
      % \typeout{* Try: \the\minmax@baselineskip\space -> \minmax@new@HT}%
      \ifdim\minmax@new@HT>\minmax@HT\relax
        \edef\minmax@lower{\the\minmax@baselineskip}%
        % \typeout{* Low: \minmax@lower}%
      \else
        \ifdim\minmax@new@HT<\minmax@HT\relax
          \edef\minmax@upper{\the\minmax@baselineskip}%
          % \typeout{* Upp: \minmax@upper}%
          \let\minmax@HT\minmax@new@HT
        \else
          \minmax@todo@false
        \fi
      \fi
      \ifdim\minmax@upper=\minmax@baselineskip 
        \minmax@todo@false
      \fi
    \repeat
    \typeout{* Min: \the\minmax@baselineskip}%
    \unhcopy0 
  \endgroup
}
\newenvironment{minmax@test}{}{}
\def\minmax@test#1#{\@gobble}%
\makeatother

\begin{document}
\noindent
\begin{minmaxminipage}[t]{1\columnwidth}%
Just some normal text before the math. Go on a bit of a bit longer so
that this wraps into a couple of lines. I wish I had a funny joke to
tell you but I cant remember any. For example, 
$\widehat{\Omega_{YOU}^{\hat{XYZ}}}=\mathit{DYNAMICS}$
is a model that I would
like to examine. OK now lets do some more filler text here to see
another line and check out the spacing. If you read this far you
deserve an award.%
\end{minmaxminipage}
\end{document}

\baselineskip可以找到一个较小的值:

* Max: 16.20827pt
* Min: 15.70175pt

结果 最小最大

相关内容