LaTeX forum ⇒ Math & Science ⇒ Force Equation Alignment to left Side Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
JustA_LaTeXusr
Posts: 42
Joined: Tue Jul 23, 2013 6:48 pm

Force Equation Alignment to left Side

I browsed the many threads and most referred to flalign. I also don't want equals signs on every line. Here is my MWE.
\documentclass[fleqn]{article}
\usepackage[fleqn]{amsmath}

\begin{document}
\begin{flalign*}
& var1 &=& var2 & & & \\
& & & (var3) (var4) & & & \\
& & & (var5) (var6) & & & \\
& & & (var7) & (var8) 100 - 100 & & \\
& &=& 173 & & &\\
\end{flalign*}

\begin{flalign*}
var1 &=& var2 & & & \\
& & (var3) (var4) & & & \\
& & (var5) (var6) & & & \\
& & (var7) & (var8) 100 - 100 & & \\
&=& 173 & & &\\
\end{flalign*}

% Snipped from this forum, but I don't want
% equals on every  line
\begin{flalign*}
& \lambda = \lambda_1 + \lambda_2 &\\
& \Lambda = \Lambda_1 + \Lambda_2 &
\end{flalign*}

\begin{flalign*}
\lambda &= \lambda_1 + \lambda_2 &\\
&= \Lambda &\\
&= \Lambda_1 + \Lambda_2 &
\end{flalign*}
\end{document}

I have extra ampersands because I thought dummy columns might help, but they don't appear to.

Instead of left-aligning, the entire content of each column seem to right-align.

Thanks for pointing out what my error is (I'm sure it's my error). I will resort to {array} as an alternative for now.

LaTeXguide.org • LaTeX-Cookbook.net

kaiserkarl13
Posts: 665
Joined: Tue Mar 25, 2008 5:02 pm

Force Equation Alignment to left Side

It's not really clear what you're looking for. I think (?) this is what you were looking for:
\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{flalign*}
var1 ={}& var2 & \\
& (var3) (var4) & \\
& (var5) (var6) & \\
& (var7) \quad (var8) 100 - 100 & \\
={}& 173\\
\end{flalign*}
\end{document}


The {} after the equals sign tells TeX to insert space around the equals sign as if it were a binary operator (without the braces, there is no right-hand-side, so TeX treats it as unary). The & character then aligns all the lines at that spot. The & at the END of the line is a signal to the flalign environment that stuff to the right of it (in this case, nothing) is aligned right, while the stuff to the left is aligned left.

If that's not what you're trying to do, please provide an example of what the output should look like.

JustA_LaTeXusr
Posts: 42
Joined: Tue Jul 23, 2013 6:48 pm

Force Equation Alignment to left Side

Thanks, kaiserkar. I tried your coding pattern on my case, and it didn't quite get the alignment I was seeking. However, I managed to get it using an array. Here is the code with your coding pattern, your pattern applied to my case, and then a minimal example of the end result I'm seeking. I think I'll continue using \array unless there is a simple way to do it with flalign. I just thought flalign was preferred because I am in fact dealing with an equation rather than a generic array.

\documentclass[fleqn]{article}
\usepackage[fleqn]{amsmath}
\begin{document}

% kaiserkarl13
\begin{flalign*}
var1 ={}& var2 & \\
& (var3) (var4) & \\
& (var5) (var6) & \\
& (var7) \quad (var8) 100 - 100 & \\
={}& 173\\
\end{flalign*}

% kaiserkarl13 applied to my array
\begin{flalign*}
var1 ={}& var2 & \\
& (var3) (var4) & \\
& (var5) (var6) & \\
& (var7) & (var8) 100 - 100 \\
=& 173 &\\
\end{flalign*}

% desired effect
$\begin{array}{ccll} i_\textrm{New} &=& \displaystyle \rule[-1mm]{0pt}{1cm} \left( 1+ \frac{ 2.27\%}{100\%} \right) \left( 1+ \frac{ 2.68\%}{100\%} \right) & \\ & & \displaystyle \times \rule[-1mm]{0pt}{1cm} \left( 1+ \frac{ 2.85\%}{100\%} \right) \left( 1+ \frac{ 3.85\%}{100\%} \right) & \\ & & \displaystyle \hfill \times \rule[-1mm]{0pt}{1cm} \left( 1+ \frac{ 3.16\%}{100\%} \right) & \times 100\% - 100\% \\ \rule[-1mm]{0pt}{1cm} &=& \textrm{\large 173\%} \end{array}$

\end{document}

kaiserkarl13
Posts: 665
Joined: Tue Mar 25, 2008 5:02 pm

Force Equation Alignment to left Side  Topic is solved

I have two alternatives that provide spacings that are better than that provide by array or eqnarray:
\documentclass[fleqn]{article}
\usepackage[fleqn]{amsmath}
\begin{document}
\begin{equation*}
\begin{array}{ccll}
i_\textrm{New} &=& \displaystyle \rule[-1mm]{0pt}{1cm}
\left( 1+ \frac{ 2.27\%}{100\%} \right)
\left( 1+ \frac{ 2.68\%}{100\%} \right)
&
\\
& & \displaystyle \times \rule[-1mm]{0pt}{1cm}
\left( 1+ \frac{ 2.85\%}{100\%} \right)
\left( 1+ \frac{ 3.85\%}{100\%} \right)
&
\\
& & \displaystyle \hfill \times \rule[-1mm]{0pt}{1cm}
\left( 1+ \frac{ 3.16\%}{100\%} \right)
& \times 100\% - 100\%
\\
\rule[-1mm]{0pt}{1cm}
&=& \textrm{\large 173\%}
\end{array}
\end{equation*}
Option 1:
\begin{align*}
i_\textrm{New} ={}& \displaystyle \rule[-1mm]{0pt}{1cm}
\left( 1+ \frac{ 2.27\%}{100\%} \right)
\left( 1+ \frac{ 2.68\%}{100\%} \right)
\\
& {} \times
\left( 1+ \frac{ 2.85\%}{100\%} \right)
\left( 1+ \frac{ 3.85\%}{100\%} \right)
\\
& \displaystyle \hfill \times %\rule[-1mm]{0pt}{1cm}
\left( 1+ \frac{ 3.16\%}{100\%} \right)
\times 100\% - 100\%
\\[0.5cm]
{}={}& \textrm{\large 173\%}
\end{align*}
Option 2
\begin{align*}
i_\textrm{New} ={}&
\left( 1+ \frac{ 2.27\%}{100\%} \right)
\left( 1+ \frac{ 2.68\%}{100\%} \right)
\\
& {} \times
\left( 1+ \frac{ 2.85\%}{100\%} \right)
\left( 1+ \frac{ 3.85\%}{100\%} \right)
\\
&
\phantom{\left( 1+ \frac{ 2.85\%}{100\%} \right)}
\times \left( 1+ \frac{ 3.16\%}{100\%} \right)
\times 100\% - 100\%
\\[0.5cm]
{}={}& \textrm{\large 173\%}
\end{align*}
\end{document}


JustA_LaTeXusr
Posts: 42
Joined: Tue Jul 23, 2013 6:48 pm

Re: Force Equation Alignment to left Side

Thanks, kaiserkar13! The code is certainly more streamline. The vertical spacing takes care of itself without the need for invisible "rules" and you don't need to force displaystyle. It's also a nice reminder that one can specify a vertical spacing right after the double backslash.