[Tex/LaTex] Help with left align

amsmathequationshorizontal alignmentmath-modevertical alignment

I was trying to left align this equation by using code

$$\begin{equation}
\begin{aligned}
E_\theta(L(\delta_1(X)) &=& E_\theta[(1-\frac{b}{a+X^2}) X-\theta]^2\nonnumber\\
                        &=&E_\theta[Y-\frac{b}{a+(Y+\theta)^2}(Y+\theta)]^2\nonnumber\\
                         &=& n-2bE\frac{Y(Y+\theta)}{a+(Y+\theta)^2}+b^2E\frac{(Y+\theta)^2}{[a+(Y+\theta)^2]^2}\nonnumber\\
                         &<&n-2bE\frac{Y(Y+\theta)^2-b/2}{a+(Y+\theta)^2} \label{eq:21}\end{aligned}\end{equation}$$

However, it turns out it's still right aligned and it is labelled (1) instead of (2.1)

My preamble is

\documentclass[12pt]{article}


\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[fleqn]{amsmath}

Best Answer

You're making several errors.

  1. $$ should never be used in LaTeX (see Why is \[ ... \] preferable to $$ ... $$?)

  2. Just equation is sufficient to get an equation number

  3. Lines in aligned are never numbered by themselves

  4. The syntax is <left hand side> &= <right hand side>

  5. There is no \nonnumber command; it is \nonumber, but in this case it's not necessary

  6. The label should be outside the inner aligned

  7. The amsmath package should be loaded only once.

In the example I used \lipsum to provide some mock text and show the alignment.

More important is the correct usage of \left and \right around big fractions.

\documentclass[12pt]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[fleqn]{amsmath}
\numberwithin{equation}{section}

\usepackage{lipsum} % just for this example

\begin{document}

\section{A new section}

\lipsum*[3]
\begin{equation}\label{eq:21}
\begin{aligned}
E_\theta(L(\delta_1(X))
&= E_\theta\left((1-\frac{b}{a+X^2}) X-\theta\right)^2 \\
&=E_\theta\left(Y-\frac{b}{a+(Y+\theta)^2}(Y+\theta)\right)^2 \\
&= n-2bE\frac{Y(Y+\theta)}{a+(Y+\theta)^2}+b^2E\frac{(Y+\theta)^2}{[a+(Y+\theta)^2]^2}\\
&<n-2bE\frac{Y(Y+\theta)^2-b/2}{a+(Y+\theta)^2}
\end{aligned}
\end{equation}
\lipsum[3]
\end{document}

enter image description here