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.

I've read a few posts here about center math equations and all of them make use of

\begin{align} *Math symbols* \end{align}

Now I've included the \usepackage{amsmath} before the begin document line. But I keep getting this error:

enter image description here

Any ideas guys? I'm a latex noob

Here is some code:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\section{Situation 1}

\begin{align}
$J_{(j)} = \sum\limits_{i:r(i,j)=1} ((\theta\textsuperscript{(j)})\textsuperscript{T}x\textsuperscript{(i)} - Y_{i,j})^2 + \frac{\lambda}{2}\sum\limits_{k=1}^n(\theta_k\textsuperscript{(j)})^2$
\end{align}

\end{document}
share|improve this question
1  
Can you post a MWE (see here) that illustrates your problem? A basic program works for me...: \documentclass{article} \usepackage{amsmath} \begin{document} \begin{align} x = y \end{align} \end{document} –  cslstr May 22 at 16:07
5  
Take out the $ around your math... \begin{align} puts you in math mode already. –  cslstr May 22 at 16:12
    
Equations are centered by default. You need align for multiline equations. You may find useful examples here: tex.stackexchange.com/questions/98397/enumerate-formulas/… –  Ethan Bolker May 22 at 16:17
    
@cslstr do you mind writing up a post so that I can accept the answer? THANK YOU!!!!! –  user1638809 May 22 at 16:20

1 Answer 1

up vote 5 down vote accepted

TeX is great for math typesetting; so it's unlikely that a formula like that is so complicated to input:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\section{Situation 1}

\begin{equation*}
J_{(j)} = 
  \sum_{i:r(i,j)=1} \bigl((\theta^{(j)})^{T} x^{(i)} - Y_{i,j}\bigr)^2 + 
  \frac{\lambda}{2}\sum_{k=1}^{n}\bigl(\theta_{k}^{(j)}\bigr)^2
\end{equation*}

\end{document}

There should never be \textsuperscript inside a formula.

Using \bigl and \bigr in the first formula makes the parentheses slightly bigger, which is good for reading in this case. Since they are almost necessary in the furst summation, I used them also in the second one, for symmetry.

enter image description here

The align environment is for multiline displays; if you want the equation numbered, then use equation instead of equation*.

But in any case, the contents of equation, align and similar environments is already assumed to be math, so adding $ will give errors.

share|improve this answer

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.