如何测量直线方程的高度

如何测量直线方程的高度

如何测量下列内联方程的高度?

这里的等式包含分数,所以它的高度应该超出正常的文本高度,所以我想测量内联等式的精确高度。

这个内联方程的高度${\text{IR}}u_{i,t} \le \frac{{q_{i,t} - q_{i,t - 1} + M_{i} + m_{i} - 0.5ru_{i} }}{{M_{i} + m_{i} + 0.5ru_{i} }}$是??

答案1

适当的 LaTeX 习惯用法应该是这样的

\newlength{\mathmeasureheight}
\newlength{\mathmeasuredepth}
\newcommand{\measuremath}[1]{%
  \settoheight{\mathmeasureheight}{$#1$}%
  \settodepth{\mathmeasuredepth}{$#1$}%
}

但之后你应该利用这些信息做一些事情。假设你想根据高度或深度做出决定:如果其中一个大于支柱的相应尺寸,我们将在显示中排版公式,否则以内联方式排版。

\documentclass{article}
\usepackage{amsmath}

\newlength{\mathmeasureheight}
\newlength{\mathmeasuredepth}
\newcommand{\mathmeasure}[1]{%
  \settoheight{\mathmeasureheight}{$#1$}%
  \settodepth{\mathmeasuredepth}{$#1$}%
  \ifdim\mathmeasureheight<\ht\strutbox
    \ifdim\mathmeasuredepth<\dp\strutbox
      $#1$%
    \else
      \[#1\]%
    \fi
  \else
    \[#1\]%
  \fi
}

\begin{document}

Dummy text here dummy text here dummy text here.
The height of this inline equation 
\mathmeasure{\mathrm{IR}u_{i,t} \le 
\frac{{q_{i,t} - q_{i,t - 1} + M_{i} + m_{i} - 0.5ru_{i} }}{{M_{i} + m_{i} + 0.5ru_{i} }}}
doesn't fit in the line.
Dummy text here dummy text here dummy text here.
Dummy text here dummy text here dummy text here.

Dummy text here dummy text here dummy text here.
The height of this inline equation 
\mathmeasure{\frac{a}{b}}
fits in the line.
Dummy text here dummy text here dummy text here.
Dummy text here dummy text here dummy text here.

\end{document}

在此处输入图片描述

答案2

这里的等式包含分数,所以它的高度应该超出正常的文本高度,所以我想测量内联等式的精确高度。

\frac虽然如果内联方程包含表达式,其高度(顺便说一下,深度也是如此)确实会增加,但不对这种增加会自动要求您(或 LaTeX...)做一些特殊的事情。如下图上三分之一所示,内联方程的存在并不需要增加行距。

希望该屏幕截图也能说明,增加行距并非绝对必要,但这并不意味着\frac在段落内使用较长的表达式实际上是个好主意。屏幕截图中间三分之一显示了相同的内联方程,但使用内联分数符号(又称“斜线符号”)代替\frac符号。我希望你会同意,使用内联分数方程的段落可读性更强。

最后的评论:如果您确实需要用\frac符号显示等式,请使用显示数学环境进行显示。

在此处输入图片描述

\documentclass{article}
\usepackage{lipsum}
\begin{document}

\lipsum[1][1-3]
$\mathrm{IR}u_{i,t} \le \frac{{q_{i,t} - q_{i,t - 1} + M_{i} + m_{i} - 0.5ru_{i} }}{{M_{i} + m_{i} + 0.5ru_{i} }}$
\lipsum[1][4-6]

\bigskip
\lipsum[1][1-3]
$\mathrm{IR}u_{i,t} \le (q_{i,t} - q_{i,t - 1} + M_{i} + m_{i} - 0.5ru_{i})/(M_{i} + m_{i} + 0.5ru_{i})$
\lipsum[1][4-6]

\bigskip
\lipsum[1][1-3]
\[
\mathrm{IR}u_{i,t} \le \frac{q_{i,t} - q_{i,t - 1} + M_{i} + m_{i} - 0.5ru_{i} }{M_{i} + m_{i} + 0.5ru_{i} }
\]
\lipsum[1][4-6]

\end{document} 

答案3

您可以将公式设置为box0并测量其\ht0\dp0。例如:

\newdimen\htmath
\newdimen\dpmath

\def\measure$#1${\setbox0=\hbox{$#1$}\htmath=\ht0 \dpmath=\dp0 \unhbox0 }

The height of this inline equation
\measure ${\rm IR} u_{i,t} \le { q_{i,t} - q_{i,t-1} + M_i + m_i - 0.5ru_i \over M_i + m_i + 0.5ru_i }$
is \the\htmath+\the\dpmath.

\bye

相关内容