7

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}
7
  • Welcome to TeX.SX! If you indent the code by four spaces, as I did in my edit, it is rendered with colored syntax.
    – egreg
    Jul 26, 2013 at 16:49
  • 2
    Regarding your use of $$, see Why is \[\] preferable to $$?
    – Werner
    Jul 26, 2013 at 16:52
  • It seems like you're using the older eqnarray notation for alignment. Use only one ampersand & to the left of the binary operator/relation to mark the appropriate alignment.
    – Werner
    Jul 26, 2013 at 16:54
  • You mean to replace $=$ by $=? Jul 26, 2013 at 16:55
  • Yep, this solved the left align issue. However, I still couldn't get label (2.1). Any ideas? Jul 26, 2013 at 16:57

3 Answers 3

4

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

4

several problems here ...

  • if you use \begin{equation} ... \end{equation} you shouldn't use $$. (besides, \[ ... \] should be used instead of $$ if you do want an unnumbered equation.)

  • \nonumber (not \nonnumber) isn't needed if you're using aligned. since aligned "groups" all the lines within it, any appearance there of \nonumber will suppress the equation number.

  • the extra & following the = or < is what is forcing everything on the right-hand side to the right. for aligned you should use only one &, before the sign of relation. the extra & is the eqnarray convention; the single & is the proper method for the structures provided by amsmath (where aligned is defined).

  • move the label outside the aligned; it belongs at the equation level. this won't affect whether or not the equation number is printed, but it makes more sense to someone else reading the input code.

2

I'm not clear on what you mean when you say left aligned, but here's my attempt. Also, I wasn't clear if you wanted to explicitly number the equation, like I've done below, or if you want the equations to follow section numbers.

See the wiki book for some more explanation on alignment and equation numbering.

\documentclass[12pt,fleqn]{article}

\usepackage{amsmath}

\begin{document}
\begin{align*}
E_\theta(L(\delta_1(X)) &= E_\theta[(1-\frac{b}{a+X^2}) X-\theta]^2 \\
                        &=E_\theta[Y-\frac{b}{a+(Y+\theta)^2}(Y+\theta)]^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} \label{eq:21} \tag{2.1}
\end{align*}
\end{document}

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .