3

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

2
  • 2
    Use the cases environment from amsmath.
    – Davislor
    Nov 28, 2020 at 6:34
  • Welcome to TeX.SX! 😊 You can have a look at our starter guide to familiarize yourself further with our format. Please avoid "do this for me" questions, you should at least post a minimal working example (MWE) to show your efforts. Also, please mark and upvote the correct answer. Enjoy this community!
    – Holene
    Nov 28, 2020 at 7:39

2 Answers 2

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

4
  • Nice answer. An image of the output would be handy!
    – Davislor
    Nov 28, 2020 at 6: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, 2020 at 6:39
  • 2
    align is not intended for single equation.
    – Zarko
    Nov 28, 2020 at 7: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, 2020 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

2
  • Neat! Curious to the thought behind the \, extra space between the indices?
    – Holene
    Nov 28, 2020 at 7:41
  • 2
    @Holene, oh, they are superfluous ... deleted now. Thank you very much to point me on this.
    – Zarko
    Nov 28, 2020 at 7:58

Not the answer you're looking for? Browse other questions tagged .