我正在尝试输入公式,该公式需要一些文本注释。我在数学模式下使用 \text{} 命令执行此操作。但是,自动换行不起作用。我该怎么办?代码示例:
$P^1_{r,s}=\sum\limits_{i=r}^n{P(i\text{ applicant is selected and is the best})}=\sum\limits_{i=r}^n{P(i\text{ applicant is the best})*P(i\text{ is selected | is the best})}.$.
正如您在屏幕截图中看到的,没有使用自动换行,并且行被截断。提前致谢。
答案1
我将输入如下所示的公式:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\noindent Text before.
\begin{align*}
P_{r, s}^{1}
&= \sum_{i = r}^{n} P(\text{$i$ applicant is selected and is the best})\\
&= \sum_{i = r}^{n} P(\text{$i$ applicant is the best}) \cdot P(\text{$i$ is selected $\mid$ is the best})
\end{align*}
Text after.
\end{document}
如果要将方程式左对齐,可以执行以下操作:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\noindent Text before.
\begin{flalign*}
P_{r, s}^{1}
&= \sum_{i = r}^{n} P(\text{$i$ applicant is selected and is the best}) &\\
&= \sum_{i = r}^{n} P(\text{$i$ applicant is the best}) \cdot P(\text{$i$ is selected $\mid$ is the best})
\end{flalign*}
Text after.
\end{document}
答案2
TeX 在二进制和关系运算符后插入断点,并带有惩罚\binoppenalty
和\relpenalty
。但是,子公式不能跨行拆分。一对花括号会创建一个子公式,如问题示例中所示。因此*
不会创建断点。
如果您想要在公式的文本部分内设置断点,那么可以在数学之外给出文本。
下面的示例通过将示例放入太窄的范围内来强制在断点处换行minipage
:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\begin{document}
\begin{minipage}{1mm}
$P^1_{r,s}=\sum\limits_{i=r}^n{P(i\text{ applicant is selected and is the
best})}=\sum\limits_{i=r}^n{P(i\text{ applicant is the best})*P(i\text{ is
selected | is the best})}$.
\end{minipage}
\smallskip\hrule\smallskip
% Remove subformula
\begin{minipage}{1mm}
$P^1_{r,s}=\sum\limits_{i=r}^n{P(i\text{ applicant is selected and is the
best})}=\sum\limits_{i=r}^n{P(i\text{ applicant is the best})}*{P(i\text{ is
selected | is the best})}$.
\end{minipage}
\smallskip\hrule\smallskip
% Text outside math
\begin{minipage}{1mm}
$P^1_{r,s}=\sum\limits_{i=r}^n P(i$ applicant is selected and is
the best$)=\sum\limits_{i=r}^n P(i$ applicant is the best$) * P(i$
is selected | is the best$)$.
\end{minipage}
\end{document}