3

how can I write this formula by latex enter image description here

Eng.sh
  • 69
  • 1
  • 7

2 Answers2

5

One way is to use:

\begin{align}
p_{i \, j} = \begin{cases} \frac{1}{|p_{i}|} & \text{if $P_{i}$ links to $P_{j}$} \\
0 & \text{otherwise} \end{cases}
\end{align}

where align is used for spacing around the equation(s) or an inline version is:

 $$ p_{i \, j} = \begin{cases} \frac{1}{|p_{i}|} & \text{if $P_{i}$ links to $P_{j}$} \\
 0 & \text{otherwise} \end{cases} $$

The results can be viewed as (in their respective order): enter image description here

Leucippus
  • 1,636
  • Nice answer. An image of the output would be handy! – Davislor Nov 28 '20 at 06:38
  • One minor tweak: you might want \lvert p_{i} \rvert, so as to space the absolute-value bars as left and right delimiters. – Davislor Nov 28 '20 at 06:39
  • 2
    align is not intended for single equation. – Zarko Nov 28 '20 at 07:55
  • Usage of $$ is deprecated in LaTeX. Instead it you should use \[ and \] or \begin{equation} and \end{equation} (see my answer). You should provide an MWE, which reproduce showed image. And let me repeat, your use of align in the first example is wrong. – Zarko Nov 28 '20 at 21:13
2

With use of cases* and/or dcases?defined in the mathtools package and defining \abs{...} as pair of delimiters for absolute value:

\documentclass[12pt]{article}
\usepackage{mathtools}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}

\begin{document} \begin{equation} p_{ij} = \begin{cases} \dfrac{1}{\abs{p_{i}}} & if $P_{i}$ links to $P_{j}$ \ 0 & otherwise \end{cases} \end{equation} or \begin{equation} p_{ij} = \begin{dcases} \frac{1}{\abs{p_{i}}} & if $P_{i}$ links to $P_{j}$ \ 0 & otherwise \end{dcases} \end{equation}

\end{document}

enter image description here

Zarko
  • 296,517