如何在公式中的文本中添加空格?

如何在公式中的文本中添加空格?

我有一系列 TeX 公式,其中作者在文本中放入了空格,例如:

{\rm{Maximum credit}} = {{\mathop {{\rm{Net income from sources}}}\limits_{{\rm{without the United States}}} } \over {{\rm{Total net income}}}} \times \mathop {{\rm{United States tax on}}}\limits_{{\rm{total income}}}

使用pdfTeX,文本呈现时不包含空格:

在此处输入图片描述

我需要对 TeX 公式做什么才能显示空格?

答案1

我建议你\text对不需要换行的 2 个字符串使用说明,\parbox对需要换行的 2 个字符串使用指令。\text和都\parbox以文本模式排版其参数,这正是你想要的。

备注:正如@barbarabeeton 在评论中指出的那样,如果这种类型的“冗长的等式”有可能出现在以斜体为主要字体形状的环境中(例如,类似定理的环境内部),则应使用\textup\textrm代替,\text以确保使用直立字符而不是斜体字符。

\parboxes对于下面的示例代码,我经过最少的反复试验后选择了宽度。

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath} % for '\text' macro
\begin{document}

\[
\text{Maximum credit} = 
\frac{\parbox{4cm}{\centering Net income from sources 
      without the United States\strut}}{%
      \text{Total net income}} 
\times 
\parbox{2.75cm}{\centering United States tax on total income}
\]

\end{document}

答案2

  • 加载amsmath包 (或者mathtools也加载amsmath)。
  • amsmath软件包提供了该功能\text{}
  • \text{}函数旨在用于数学中并尊重空格,例如\text{Net income from sources}
  • 或者,使用~创建空格,例如\mathrm{without~the~United~States}。请注意,我将其更改\rm\mathrm因为这是更合适的命令,请参阅这里。 看这里寻找 的替代方案~

答案3

如果您正在使用 LaTeX,请注意它\rm在大约 30 年前就已被宣布过时并被弃用。

您应该使用它tabular来完成这项工作,这样您就不需要猜测材料的宽度了。

\documentclass{article}
\usepackage{amsmath}

\newcommand{\wordvar}[1]{%
  \textup{\begin{tabular}{@{}c@{}}#1\end{tabular}}%
}

\begin{document}

\[
\wordvar{Maximum credit} =
\frac{\wordvar{Net income from sources \\ without the United States}}
     {\wordvar{Total net income}}
\times
\wordvar{United States tax on \\ total income}
\]

\end{document}

在此处输入图片描述

如果您使用的是纯 TeX,则可以用类似的方式完成。

\def\wordvar#1{%
  \vcenter{\rm\ialign{\hfil\strut##\hfil\cr#1\crcr}}%
}

$$
\wordvar{Maximum credit} =
{
 \wordvar{Net income from sources \cr without the United States}
 \over
 \wordvar{Total net income}
}
\times
\wordvar{United States tax on \cr total income}
$$

\bye

相关内容