TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Linebreak in equations

I am very new to latex, its been a super frustrating I spend almost close to two hours on getting a new line inside the math block

\[{P(g(X) \neq Y |X = x) = 1 − P (Y = g(X)|X = x)}
{= 1 - [P(Y=1,g(X)=1|X=x) + P(Y=1,g(X)=1|X=x)]}
{= 1 − E[1_{Y =1} 1_{g(X)=1}|X = x] + E[1_{Y =0} 1{g(X)=0}|X = x]}

Also I used underscores to show the subscript but somehow that doesn't work either.

It would be great if someone could give a pointer.

share|improve this question

marked as duplicate by Werner, Stefan Kottwitz Oct 6 '12 at 20:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

See here and or here – Scott H. Oct 6 '12 at 17:03
What doesn't work with your subscript? Does it work when you use my code below? – Juri Robl Oct 6 '12 at 17:13
up vote 5 down vote accepted

Use a multiline environment from the amsmath package, like align:

\{P(g(X)\neq& Y \mid X=x) = 1-P(Y=g(X)\mid X=x)\}\\
\{=& 1 - [P(Y=1,g(X)=1\mid X=x)\\
&+ P(Y=1,g(X)=1\mid X=x)]\}\\
\{=& 1 - E\left[1_{Y =1} 1_{g(X)=1}\mid X = x\right]\\
&+ E\left[1_{Y =0} 1{g(X)=0}\mid X = x\right]\}

If you don't want your equation numbered, use align* instead of align.

Instead of directly using the amsmath package, you can instead use mathtools. It tries to fix some bugs in amsmath and provides additional symbols and options to change the layout of equations.

share|improve this answer
+1 but this gives an overfull hbox; can you show the OP how to fix that, perhaps break the second line into two... – cmhughes Oct 6 '12 at 16:59
And using \bigl(, \bigr) and \bigm| also improve the readability. – Gonzalo Medina Oct 6 '12 at 17:03
those curly brackets I have those are not to seperate a block but I really want to add them in the equation how can i get that to work. – find-missing-semicolon Oct 6 '12 at 17:22
Just escape them \{...\} – Juri Robl Oct 6 '12 at 17:26
can you also tell me how to get rid of the equation number..? thanks bunch – find-missing-semicolon Oct 6 '12 at 18:21

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