2

This is difficult for me with all these $ signs. Now, where is the problem in the following MWE?

\documentclass{article}%

\usepackage{amsmath}%
\usepackage{amsfonts}%
\usepackage{amssymb}%
\usepackage{graphicx}
\usepackage{comment}

\begin{document}

\varphi_{nk}(x,y) = \left\{
\begin{array}{c l}
1 & $x_{k}\succ_{n} y_{k}$\\
1/2 & $x_{k} \sim_{n} y_{k}$\\
0 & $x_{k}\prec_{n} y_{k}$
\end{array}
\right.

So \textit{n} is \varphi_{n}(x,y)= \sum_{k}\varphi_{nk}


\end{document}

Also a more general question related to Tex.sx. How can I copy the code to the question box, without having to press space bar 4 times for each line to indent it?

As a follow up, in case I would like to insert the word 'if' in every case (piece) of the function above, how can I do so? Eg

...1/2 & if $x_{k}\succ_{n} y_{k}$

doesn't seem to work as the 'if' is conjoined.

David Carlisle
  • 757,742

2 Answers2

5

Don't use $ within an array environment, since the array environment is completely in math mode.

\documentclass{article}
\usepackage{amsmath}%
\usepackage{amsfonts}%
\usepackage{amssymb}%
\begin{document}
\[
\varphi_{nk}(x,y) = \left\{
\begin{array}{c l}
1 & x_{k}\succ_{n} y_{k}\\
1/2  x_{k} \sim_{n} y_{k}\\
0 & x_{k}\prec_{n} y_{k}
\end{array}
\right.
\]
So $n$ is $\varphi_{n}(x,y)= \sum_{k}\varphi_{nk}$.
\end{document}

Further tips regarding your example:

  • Use math expressions such as \varphi_{nk}(x,y) in math mode, either within text (inline) such as by $...$ or \( ... \) or in displayed mode, such as by \[ ... \] in my example.

  • Don't use empty lines before or after such displayed math formulas.

  • Don't use \textit for simulating math mode.

Have a look at the Mathmode tag wiki for links to tutorials, useful packages and resources on this site.

Moriambar
  • 11,466
Stefan Kottwitz
  • 231,401
4

You should read Math mode (H. Voß). With $...$ you always use the inline math.

You example can be modified with the cases-environment:

\documentclass{article}%

\usepackage{amsmath}% \usepackage{amsfonts}% \usepackage{amssymb}% \usepackage{graphicx} \usepackage{comment}

\begin{document} \begin{equation} \varphi_{nk}(x,y) = \left{ \begin{array}{c l} 1 & x_{k}\succ_{n} y_{k}\ 1/2 & x_{k} \sim_{n} y_{k}\ 0 & x_{k}\prec_{n} y_{k} \end{array} \right. \end{equation} So \textit{n} is$ \varphi_{n}(x,y)= \sum_{k}\varphi_{nk}$

\begin{equation} \varphi_{nk}(x,y) = \begin{cases} 1 & x_{k}\succ_{n} y_{k}\ 1/2 & x_{k} \sim_{n} y_{k}\ 0 & x_{k}\prec_{n} y_{k} \end{cases} \end{equation} So \textit{n} is$ \varphi_{n}(x,y)= \sum_{k}\varphi_{nk}$ \end{document}

David Carlisle
  • 757,742
Marco Daniel
  • 95,681