LaTeX forum ⇒ Math & ScienceForce 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

Postby JustA_LaTeXusr » Tue Jul 23, 2013 6:59 pm

I browsed the many threads and most referred to flalign. I also don't want equals signs on every line. Here is my MWE.
  1. \documentclass[fleqn]{article}
  2. \usepackage[fleqn]{amsmath}
  3.  
  4. \begin{document}
  5. \begin{flalign*}
  6. & var1 &=& var2 & & & \\
  7. & & & (var3) (var4) & & & \\
  8. & & & (var5) (var6) & & & \\
  9. & & & (var7) & (var8) 100 - 100 & & \\
  10. & &=& 173 & & &\\
  11. \end{flalign*}
  12.  
  13. \begin{flalign*}
  14. var1 &=& var2 & & & \\
  15. & & (var3) (var4) & & & \\
  16. & & (var5) (var6) & & & \\
  17. & & (var7) & (var8) 100 - 100 & & \\
  18. &=& 173 & & &\\
  19. \end{flalign*}
  20.  
  21. % Snipped from this forum, but I don't want
  22. % equals on every line
  23. \begin{flalign*}
  24. & \lambda = \lambda_1 + \lambda_2 &\\
  25. & \Lambda = \Lambda_1 + \Lambda_2 &
  26. \end{flalign*}
  27.  
  28. \begin{flalign*}
  29. \lambda &= \lambda_1 + \lambda_2 &\\
  30. &= \Lambda &\\
  31. &= \Lambda_1 + \Lambda_2 &
  32. \end{flalign*}
  33. \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.

Tags:

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

Postby kaiserkarl13 » Thu Jul 25, 2013 1:38 am

It's not really clear what you're looking for. I think (?) this is what you were looking for:
  1. \documentclass{article}
  2. \usepackage{amsmath}
  3.  
  4. \begin{document}
  5. \begin{flalign*}
  6. var1 ={}& var2 & \\
  7. & (var3) (var4) & \\
  8. & (var5) (var6) & \\
  9. & (var7) \quad (var8) 100 - 100 & \\
  10. ={}& 173\\
  11. \end{flalign*}
  12. \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

Postby JustA_LaTeXusr » Mon Jul 29, 2013 5:44 pm

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.

  1. \documentclass[fleqn]{article}
  2. \usepackage[fleqn]{amsmath}
  3. \begin{document}
  4.  
  5. % kaiserkarl13
  6. \begin{flalign*}
  7. var1 ={}& var2 & \\
  8. & (var3) (var4) & \\
  9. & (var5) (var6) & \\
  10. & (var7) \quad (var8) 100 - 100 & \\
  11. ={}& 173\\
  12. \end{flalign*}
  13.  
  14. % kaiserkarl13 applied to my array
  15. \begin{flalign*}
  16. var1 ={}& var2 & \\
  17. & (var3) (var4) & \\
  18. & (var5) (var6) & \\
  19. & (var7) & (var8) 100 - 100 \\
  20. =& 173 &\\
  21. \end{flalign*}
  22.  
  23. % desired effect
  24. \[
  25. \begin{array}{ccll}
  26. i_\textrm{New} &=& \displaystyle \rule[-1mm]{0pt}{1cm}
  27. \left( 1+ \frac{ 2.27\%}{100\%} \right)
  28. \left( 1+ \frac{ 2.68\%}{100\%} \right)
  29. &
  30. \\
  31. & & \displaystyle \times \rule[-1mm]{0pt}{1cm}
  32. \left( 1+ \frac{ 2.85\%}{100\%} \right)
  33. \left( 1+ \frac{ 3.85\%}{100\%} \right)
  34. &
  35. \\
  36. & & \displaystyle \hfill \times \rule[-1mm]{0pt}{1cm}
  37. \left( 1+ \frac{ 3.16\%}{100\%} \right)
  38. & \times 100\% - 100\%
  39. \\
  40. \rule[-1mm]{0pt}{1cm}
  41. &=& \textrm{\large 173\%}
  42. \end{array}
  43. \]
  44.  
  45. \end{document}

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

Postby kaiserkarl13 » Wed Jul 31, 2013 5:18 am

I have two alternatives that provide spacings that are better than that provide by array or eqnarray:
  1. \documentclass[fleqn]{article}
  2. \usepackage[fleqn]{amsmath}
  3. \begin{document}
  4. \begin{equation*}
  5. % Your code using array
  6. \begin{array}{ccll}
  7. i_\textrm{New} &=& \displaystyle \rule[-1mm]{0pt}{1cm}
  8. \left( 1+ \frac{ 2.27\%}{100\%} \right)
  9. \left( 1+ \frac{ 2.68\%}{100\%} \right)
  10. &
  11. \\
  12. & & \displaystyle \times \rule[-1mm]{0pt}{1cm}
  13. \left( 1+ \frac{ 2.85\%}{100\%} \right)
  14. \left( 1+ \frac{ 3.85\%}{100\%} \right)
  15. &
  16. \\
  17. & & \displaystyle \hfill \times \rule[-1mm]{0pt}{1cm}
  18. \left( 1+ \frac{ 3.16\%}{100\%} \right)
  19. & \times 100\% - 100\%
  20. \\
  21. \rule[-1mm]{0pt}{1cm}
  22. &=& \textrm{\large 173\%}
  23. \end{array}
  24. \end{equation*}
  25. Option 1:
  26. \begin{align*}
  27. i_\textrm{New} ={}& \displaystyle \rule[-1mm]{0pt}{1cm}
  28. \left( 1+ \frac{ 2.27\%}{100\%} \right)
  29. \left( 1+ \frac{ 2.68\%}{100\%} \right)
  30. \\
  31. & {} \times
  32. \left( 1+ \frac{ 2.85\%}{100\%} \right)
  33. \left( 1+ \frac{ 3.85\%}{100\%} \right)
  34. \\
  35. & \displaystyle \hfill \times %\rule[-1mm]{0pt}{1cm}
  36. \left( 1+ \frac{ 3.16\%}{100\%} \right)
  37. \times 100\% - 100\%
  38. \\[0.5cm]
  39. {}={}& \textrm{\large 173\%}
  40. \end{align*}
  41. Option 2
  42. \begin{align*}
  43. i_\textrm{New} ={}&
  44. \left( 1+ \frac{ 2.27\%}{100\%} \right)
  45. \left( 1+ \frac{ 2.68\%}{100\%} \right)
  46. \\
  47. & {} \times
  48. \left( 1+ \frac{ 2.85\%}{100\%} \right)
  49. \left( 1+ \frac{ 3.85\%}{100\%} \right)
  50. \\
  51. &
  52. \phantom{\left( 1+ \frac{ 2.85\%}{100\%} \right)}
  53. \times \left( 1+ \frac{ 3.16\%}{100\%} \right)
  54. \times 100\% - 100\%
  55. \\[0.5cm]
  56. {}={}& \textrm{\large 173\%}
  57. \end{align*}
  58. \end{document}

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

Postby JustA_LaTeXusr » Thu Aug 01, 2013 7:41 pm

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.


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 2 guests