Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to type formula, which requires some textual comments. I perform this using \text{} command in math mode. However, word wrap doesn't work. What should I do? Code sample:

$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})}.$. 

As you can see on the screenshot, no word wrap is used and the line is cut. Thanks in advance.

enter image description here

share|improve this question
    
Try using a parbox around the \text command –  Christian Hupfer Apr 13 at 19:33

2 Answers 2

up vote 5 down vote accepted

I would type the formula as displayed:

\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}

output1

If you want to left-align the equations, you can do the following:

\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}

output2

share|improve this answer
    
Thanks, your answer is also helpful. Sorry, cannot upvote now, my rating is lower than 15. –  Kirill Smirnov Apr 13 at 19:52

TeX inserts breakpoints after binary and relational operators with penalties \binoppenalty and \relpenalty. However, subformulas cannot be broken across lines. A pair of curly braces create a subformula as in the example of the question. Therefore the * does not create a breakpoint.

If you want breakpoints inside the text part of the formula, then the text can be given outside math.

The following example forces line breaks at the breakpoints by putting the examples into a too narrow 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}

Result

share|improve this answer
    
Thanks for detailed answer! –  Kirill Smirnov Apr 13 at 19:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.