GeneralEquation left alignment using align

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
fenghedo
Posts: 19
Joined: Sat Oct 04, 2008 3:01 pm

Equation left alignment using align

Post by fenghedo »

Hi all,
I know one could use align in the following manner to align equations

Code: Select all

\begin{align*}
A&=B\\
 &=C
\end{align*}
But I have a long equation and I want to save some space by doing the following

Code: Select all

\begin{align*}
&A\\
&=B\\
&=C
\end{align*}
But the whole equation just got pushed way right and left a big blank space on the left.

Is there any way I could tell LaTeX to align the whole thing left?

Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Equation left alignment using align

Post by localghost »

I'm not sure whether I understand you right. You could set the fleqn (force left equation) option for the document class.


Best regards and welcome to the board
Thorsten¹
fenghedo
Posts: 19
Joined: Sat Oct 04, 2008 3:01 pm

Re: Equation left alignment using align

Post by fenghedo »

Thanks localghost. I did that and now it aligns to the left. However, LaTeX still leaves a margin of about 4 spaces to the left of the whole equation (I guess this is supposed to make it look nicer in the surrounding text environment). Please see the attached image.

Is there any way I could remove this shift?

Thanks.
Attachments
left_alignment.JPG
left_alignment.JPG (13.85 KiB) Viewed 32460 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Equation left alignment using align

Post by localghost »

Giving help would be easier if you provided the code of this excerpt shown in the screenshot.
fenghedo
Posts: 19
Joined: Sat Oct 04, 2008 3:01 pm

Equation left alignment using align

Post by fenghedo »

localghost wrote:Giving help would be easier if you provided the code of this excerpt shown in the screenshot.

Code: Select all

Then equation something can be written as
\begin{align}
&E_{ic}  = \frac{1}{N}\sum\limits_{z_k\in V} \left[
	\norm{m_f(z_k;\mu_f) + m_b(z_k+m_f(z_k;\mu_f);\mu_b)}^2 \right.\notag\\
	&\quad \left. +\norm{m_b(z_k;\mu_b) + m_f(z_k+m_b(z_k;\mu_b); \mu_f)}^2
	\right]  \notag\\
	& = \frac{1}{N}\sum\limits_{z_k\in V} \left[
	\norm{\begin{bmatrix}
		m_{fx}(z_k;\mu_{fx}) + m_{bx}(z_k+m_f(z_k;\mu_{f});\mu_{bx})\\
		m_{fy}(z_k;\mu_{fy}) + m_{by}(z_k+m_f(z_k;\mu_{f});\mu_{by})
		\end{bmatrix}}^2 \right.\notag\\
	&\quad \left. +\norm{\begin{bmatrix}
		m_{bx}(z_k;\mu_{bx}) + m_{fx}(z_k+m_b(z_k;\mu_{b}); \mu_{fx})\\
		m_{by}(z_k;\mu_{by}) + m_{fy}(z_k+m_b(z_k;\mu_{b}); \mu_{fy})
		\end{bmatrix}}^2
	\right]  \notag\\
	\end{align}
I've seen people put full width equations in double column layouts. Do you know how to do that?


Thanks. I really appreciate the help.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Equation left alignment using align

Post by Stefan Kottwitz »

Hi fenghedo,
fenghedo wrote:However, LaTeX still leaves a margin of about 4 spaces to the left of the whole equation. Is there any way I could remove this shift?
Just set \mathindent to 0pt:

Code: Select all

\setlength{\mathindent}{0pt}
Btw. in the first line of the formula above you probably want to write

Code: Select all

E_{ic} &= \frac{1}{N} ...
look at the position of the &.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Equation left alignment using align

Post by localghost »

Another way of aligning could be the following.

Code: Select all

\begin{align*}
  E_{ic}=
  \begin{split}
    & \frac{1}{N}\sum\limits_{z_k\in V} \left[\norm{m_f(z_k;\mu_f) + m_b(z_k+m_f(z_k;\mu_f);\mu_b)}^2 \right. \\
    & \left. +\norm{m_b(z_k;\mu_b) + m_f(z_k+m_b(z_k;\mu_b); \mu_f)}^2 \right]
  \end{split}\\ 
  =
  \begin{split}
    & \frac{1}{N}\sum\limits_{z_k\in V} \left[
      \norm{\begin{bmatrix}
            m_{fx}(z_k;\mu_{fx}) + m_{bx}(z_k+m_f(z_k;\mu_{f});\mu_{bx})\\
            m_{fy}(z_k;\mu_{fy}) + m_{by}(z_k+m_f(z_k;\mu_{f});\mu_{by})
          \end{bmatrix}}^2 \right. \\
    & \left. +\norm{\begin{bmatrix}
      m_{bx}(z_k;\mu_{bx}) + m_{fx}(z_k+m_b(z_k;\mu_{b}); \mu_{fx})\\
      m_{by}(z_k;\mu_{by}) + m_{fy}(z_k+m_b(z_k;\mu_{b}); \mu_{fy})
      \end{bmatrix}}^2 \right]
  \end{split}
\end{align*}
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Equation left alignment using align

Post by Juanjo »

I assume that you have defined \norm more or less by \newcommand{\norm}[1]{\left\Vert#1\right\Vert}.

The solution proposed by localghost works if you replace \begin{split} by \begin{aligned}[t], and \end{split} by \end{aligned}. Anyway, I would remark the following facts:
  • The equation number usually is vertically centered, which is not the case in your code. This can be simply achieved by replacing align by a combination of equation and split.
  • You break lines which contain brackets in such a way that the opening bracket falls in one line and the closing one, in the second line. If you use \left - \right to fix the size of brackets, it may happen that the opening and closing brackets have different sizes, depending on the mathematical surrounding expressions. I find better to manually fix sizes.
  • Since breaks happens inside a bracketed expression, the alignment point should on the left of the opening bracket.

Taking these points into account, I would propose the following code:

Code: Select all

\begin{equation}
   \begin{split}
     E_{ic}&=\!
     \begin{aligned}[t]
        \frac{1}{N}\sum_{z_k\in V} \Bigl[&\norm{m_f(z_k;\mu_f) 
         + m_b(z_k+m_f(z_k;\mu_f);\mu_b)}^2 \Bigr. \\
         \Bigl. & +\norm{m_b(z_k;\mu_b) + m_f(z_k+m_b(z_k;\mu_b); \mu_f)}^2 \Bigr]
     \end{aligned}\\ 
     &=\!
     \begin{aligned}[t]
        \frac{1}{N}\sum_{z_k\in V} \Biggl[
        &\norm{\begin{bmatrix}
            m_{fx}(z_k;\mu_{fx}) + m_{bx}(z_k+m_f(z_k;\mu_{f});\mu_{bx})\\
            m_{fy}(z_k;\mu_{fy}) + m_{by}(z_k+m_f(z_k;\mu_{f});\mu_{by})
          \end{bmatrix}}^2 \Biggr. \\
        \Biggl. & +\norm{\begin{bmatrix}
         m_{bx}(z_k;\mu_{bx}) + m_{fx}(z_k+m_b(z_k;\mu_{b}); \mu_{fx})\\
         m_{by}(z_k;\mu_{by}) + m_{fy}(z_k+m_b(z_k;\mu_{b}); \mu_{fy})
       \end{bmatrix}}^2 \Biggr].
     \end{aligned}
  \end{split}
\end{equation}
I have also added a point at the end. Mathematical expressions should be punctuated with commas and points, as done with ordinary text.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Post Reply