LaTeX forum ⇒ Math & ScienceDifficulties in aligning equations under the flalign environment Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Difficulties in aligning equations under the flalign environment

Postby Cham » Sun Feb 18, 2018 6:00 am

I'm having some glitches with the MWE code below :
  1. \documentclass[12pt]{article}
  2. \usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
  3. \usepackage{mathtools}
  4. \newcommand*{\1}{\hspace{1pt}}
  5. \newcommand*{\tsqrt}[1]{{\textstyle{\sqrt{#1}}}}
  6.  
  7. \begin{document}
  8.  
  9. Test :
  10. \begin{flalign}
  11. \mathrlap{\text{if $4 \, \omega_0^2 > \gamma^2$ :}} && \lambda &= \frac{1}{2} \1 \tsqrt{\displaystyle{4 \, \omega_0^2 - \gamma^2}}, & \\[12pt]
  12. \mathrlap{\text{if $4 \, \omega_0^2 < \gamma^2$ :}} && \kappa &= \frac{1}{2} \1 \tsqrt{\displaystyle{\gamma^2 - 4 \, \omega_0^2}}. &
  13. \end{flalign}
  14. \begin{equation}
  15. EQUATION
  16. \end{equation}
  17.  
  18. \end{document}


Here's a preview :
equs.jpg
equs.jpg (12.45 KiB) Viewed 2029 times


As you can see, the equations aren't well centered above the "EQUATION" below them. I need them to be well balanced (i.e. centered). What am I doing wrong here?

User avatar
Johannes_B
Site Moderator
Posts: 3883
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Sun Feb 18, 2018 9:28 am

The equation environment does not know the content of the box (flalign) above. So the first step is to put EQUATION into the same enviroment. The example below looks ok, but you will have some real equation there and that will need extra fiddeling.
The \mathrlap stuff looks like you are used to manual spacing anyway.

  1. \documentclass[12pt]{article}
  2. \usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
  3. \usepackage{mathtools}
  4. \newcommand*{\1}{\hspace{1pt}}
  5. \newcommand*{\tsqrt}[1]{{\textstyle{\sqrt{#1}}}}
  6.  
  7. \begin{document}
  8.  
  9. Test :
  10. \begin{flalign}
  11. \mathrlap{\text{if $4 \, \omega_0^2 > \gamma^2$ :}} && \lambda &= \frac{1}{2} \1 \tsqrt{\displaystyle{4 \, \omega_0^2 - \gamma^2}}, & \\[12pt]
  12. \mathrlap{\text{if $4 \, \omega_0^2 < \gamma^2$ :}} && \kappa &= \frac{1}{2} \1 \tsqrt{\displaystyle{\gamma^2 - 4 \, \omega_0^2}}. & \\
  13. &&& EQUATION
  14. \end{flalign}
  15.  
  16. \end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Feb 18, 2018 3:24 pm

Johannes,

what I tried to say is that the two equations in the middle should still be centered, like "EQUATION", or if there's an "align" environment, like this :
  1. \documentclass[12pt]{article}
  2. \usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
  3. \usepackage{mathtools}
  4. \newcommand*{\1}{\hspace{1pt}}
  5. \newcommand*{\tsqrt}[1]{{\textstyle{\sqrt{#1}}}}
  6.  
  7. \begin{document}
  8.  
  9. Test :
  10. \begin{flalign}
  11. \mathrlap{\text{if $4 \, \omega_0^2 > \gamma^2$ :}} && \lambda &= \frac{1}{2} \1 \tsqrt{\displaystyle{4 \, \omega_0^2 - \gamma^2}}, & \\[12pt]
  12. \mathrlap{\text{if $4 \, \omega_0^2 < \gamma^2$ :}} && \kappa &= \frac{1}{2} \1 \tsqrt{\displaystyle{\gamma^2 - 4 \, \omega_0^2}}. &
  13. \end{flalign}
  14. \begin{align}
  15. \lambda &= \frac{1}{2} \1 \tsqrt{\displaystyle{4 \, \omega_0^2 - \gamma^2}}, \\[12pt]
  16. \kappa &= \frac{1}{2} \1 \tsqrt{\displaystyle{\gamma^2 - 4 \, \omega_0^2}}.
  17. \end{align}
  18. \begin{equation}
  19. EQUATION
  20. \end{equation}
  21.  
  22. \end{document}


You should notice the offset in the middle, relative to the align and equation environments. I used the mathrlap command to try to fix this issue, but it's not enough.

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Feb 18, 2018 3:37 pm

I just noticed that the numbers are pushing the equations to the left, in the flalign environment. Why ? The same doesn't happens under the align and equation environments.

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Feb 18, 2018 5:43 pm

O well, by fizzling the equations, I fixed the alignement problem. Issue solved. :)

User avatar
Stefan Kottwitz
Site Admin
Posts: 9154
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sun Feb 18, 2018 7:55 pm

Great to hear! Do you have code or a screenshot to see the final result for me as a quiet reader in this topic? :)

Stefan
Site admin


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 3 guests