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.

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.

share|improve this question
1  
Re "question box" (code sample): Highlight the code and click the "code" button (with "{}" on it). –  lockstep Oct 1 '11 at 9:23
    
For questions about the site, please visit TeX - LaTeX Meta. –  Stefan Kottwitz Oct 1 '11 at 9:23
add comment

2 Answers

up vote 5 down vote accepted

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.

share|improve this answer
add comment

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}
share|improve this answer
add comment

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.