Math & Sciencealign* not vertically aligned on left

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Singularity
Posts: 156
Joined: Sat Jan 22, 2011 9:55 pm

align* not vertically aligned on left

Post by Singularity »

For my edification, why doesn't the align* environment in my code left justifying all of the equations the same? Look closely at the attached pic and you'll see that the align* example is not fully flush left on the two lines following the vertical dots (which are also the two lines using capital letters as subscripts).

I've tried adding double ampersands (&), like in the alignat* example. I tried adding ampersands at the beginning and end of the line, and combinations of double ampersands, beginning and end.

As you can see, I have this working adequately using alignat*. So this question is mostly for my LATEX education.

Thanks.

Code: Select all

\documentclass[12pt,fleqn,reqno]{article}
%fleqn: left align equations
%reqno: equation numbers on right
\usepackage{amsfonts,graphics,epsfig,cite}
\usepackage{amsmath,graphicx,amssymb,amsthm}
                                 
\begin{document}
\underline{\textbf{alignat*}}
\begin{alignat*}{2}
	&v_1				&&=\dot{u}_1 \\
	&v_2				&&=\dot{u}_2 \\
	&\vdots			&&						\\
	&v_N				&&=\dot{u}_N	\\
	&\dot{v}_1	&&=k(u_0-2u_1+u_2) \\
	&\dot{v}_2	&&=k(u_1-2u_2+u_3) \\
	&\vdots			&&									\\
	&\dot{v}_N	&&=k(u_{N-1}-2u_N+u_{N+1})
.\end{alignat*}

\underline{\textbf{align*}}
\begin{align*}
	v_1				&=\dot{u}_1 \\
	v_2				&=\dot{u}_2 \\
	\vdots			&						\\
	v_N				&=\dot{u}_N	\\
	\dot{v}_1	&=k(u_0-2u_1+u_2) \\
	\dot{v}_2	&=k(u_1-2u_2+u_3) \\
	\vdots			&									\\
	\dot{v}_N	&=k(u_{N-1}-2u_N+u_{N+1})
.\end{align*}
\end{document}
Attachments
Output from the code above (vertical red lines added to clarify the issue)
Output from the code above (vertical red lines added to clarify the issue)
Capture.PNG (30.46 KiB) Viewed 4583 times
Last edited by Singularity on Sat Aug 20, 2011 8:25 pm, edited 1 time in total.

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

align* not vertically aligned on left

Post by Stefan Kottwitz »

Hi,

they are left aligned, however there's a predefined indentation. You can modify it by setting

Code: Select all

\setlength{\mathindent}{0pt}
Stefan
LaTeX.org admin
Singularity
Posts: 156
Joined: Sat Jan 22, 2011 9:55 pm

align* not vertically aligned on left

Post by Singularity »

Thanks. But I may not have worded my question correctly.

Using "\setlength{\mathindent}{0pt}" moved all of the equations in the entire document to have no indent.

What I really meant to ask is how come two of the lines have a small "outdent"? Notice in the attached that two lines hang out a small amount compared to the other six lines. The line which starts "v_N=..." (the 4th line) and the last line, which starts "v dot_N=..." seem to hang farther to the left than the other lines of the align statement. Why aren't they all vertically aligned?

And now, I think I have just figured out the answer (while typing this post): the align environment, as I've coded it, aligns each line by the equal sign. If v_N is wider than v_1 and v_2, then it will extend farther left from the equal sign than the other lines. align is working as designed, the author (that's me!) is not using it correctly.

Code: Select all

\documentclass[12pt,fleqn,reqno]{article}
%fleqn: left align equations
%reqno: equation numbers on right
\usepackage{amsfonts,graphics,epsfig,cite}
\usepackage{amsmath,graphicx,amssymb,amsthm}
                                 
\begin{document}
\underline{\textbf{align*}}
\begin{align*}
   v_1         &=\dot{u}_1       \\
   v_2         &=\dot{u}_2       \\
   \vdots      &                 \\
   v_N         &=\dot{u}_N       \\
   \dot{v}_1   &=k(u_0-2u_1+u_2) \\
   \dot{v}_2   &=k(u_1-2u_2+u_3) \\
   \vdots      &                 \\
   \dot{v}_N   &=k(u_{N-1}-2u_N+u_{N+1})
.\end{align*}
\end{document}
The fix to the problem is to use alignat:

Code: Select all

\begin{alignat}{2}
  &v_1		&&=\dot{u}_1 	   \notag \\
  &v_2		&&=\dot{u}_2 	   \notag \\
  &\vdots	&&		   \notag \\
  &v_{_N}	&&=\dot{u}_{_N}	   \notag \\
  &\dot{v}_1	&&=k(u_0-2u_1+u_2) \label{eq:firstorderFPU} \\
  &\dot{v}_2	&&=k(u_1-2u_2+u_3) \notag \\
  &\vdots	&&		   \notag \\
  &\dot{v}_{_N}	&&=k(u_{_{N-1}}-2u_{_N}+u_{_{N+1}}) \notag 
.\end{alignat}
P.S. I'm going to change the subject of this thread, if possible, to better reflect my actual question (and marking it solved).
Attachments
Capture.PNG
Capture.PNG (18.7 KiB) Viewed 4578 times
Post Reply