Math & ScienceDifficulties in aligning equations under the flalign environment

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

Difficulties in aligning equations under the flalign environment

Post by Cham »

I'm having some glitches with the MWE code below :

Code: Select all

\documentclass[12pt]{article}
\usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{mathtools}
\newcommand*{\1}{\hspace{1pt}}
\newcommand*{\tsqrt}[1]{{\textstyle{\sqrt{#1}}}}

\begin{document}

Test :
	\begin{flalign}
		\mathrlap{\text{if $4 \, \omega_0^2 > \gamma^2$ :}} && \lambda &= \frac{1}{2} \1 \tsqrt{\displaystyle{4 \, \omega_0^2 - \gamma^2}}, & \\[12pt]
		\mathrlap{\text{if $4 \, \omega_0^2 < \gamma^2$ :}} && \kappa &= \frac{1}{2} \1 \tsqrt{\displaystyle{\gamma^2 - 4 \, \omega_0^2}}. &
	\end{flalign}
	\begin{equation}
		EQUATION
	\end{equation}

\end{document}
Here's a preview :
equs.jpg
equs.jpg (12.45 KiB) Viewed 15575 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?

Recommended reading 2024:

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

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

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

Difficulties in aligning equations under the flalign environment

Post by Johannes_B »

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.

Code: Select all

\documentclass[12pt]{article}
    \usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
    \usepackage{mathtools}
    \newcommand*{\1}{\hspace{1pt}}
    \newcommand*{\tsqrt}[1]{{\textstyle{\sqrt{#1}}}}
     
    \begin{document}
     
    Test :
    	\begin{flalign}
    		\mathrlap{\text{if $4 \, \omega_0^2 > \gamma^2$ :}} && \lambda &= \frac{1}{2} \1 \tsqrt{\displaystyle{4 \, \omega_0^2 - \gamma^2}}, & \\[12pt]
    		\mathrlap{\text{if $4 \, \omega_0^2 < \gamma^2$ :}} && \kappa &= \frac{1}{2} \1 \tsqrt{\displaystyle{\gamma^2 - 4 \, \omega_0^2}}. & \\ 
    	&&&	EQUATION
    	\end{flalign}
     
    \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: 937
Joined: Sat Apr 02, 2011 4:06 pm

Difficulties in aligning equations under the flalign environment

Post by Cham »

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 :

Code: Select all

\documentclass[12pt]{article}
\usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{mathtools}
\newcommand*{\1}{\hspace{1pt}}
\newcommand*{\tsqrt}[1]{{\textstyle{\sqrt{#1}}}}

\begin{document}

Test :
	\begin{flalign}
		\mathrlap{\text{if $4 \, \omega_0^2 > \gamma^2$ :}} && \lambda &= \frac{1}{2} \1 \tsqrt{\displaystyle{4 \, \omega_0^2 - \gamma^2}}, & \\[12pt]
		\mathrlap{\text{if $4 \, \omega_0^2 < \gamma^2$ :}} && \kappa &= \frac{1}{2} \1 \tsqrt{\displaystyle{\gamma^2 - 4 \, \omega_0^2}}. &
	\end{flalign}
	\begin{align}
		\lambda &= \frac{1}{2} \1 \tsqrt{\displaystyle{4 \, \omega_0^2 - \gamma^2}}, \\[12pt]
		\kappa &= \frac{1}{2} \1 \tsqrt{\displaystyle{\gamma^2 - 4 \, \omega_0^2}}.
	\end{align}
	\begin{equation}
		EQUATION
	\end{equation}

\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: 937
Joined: Sat Apr 02, 2011 4:06 pm

Difficulties in aligning equations under the flalign environment

Post by Cham »

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: 937
Joined: Sat Apr 02, 2011 4:06 pm

Difficulties in aligning equations under the flalign environment

Post by Cham »

O well, by fizzling the equations, I fixed the alignement problem. Issue solved. :)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10322
Joined: Mon Mar 10, 2008 9:44 pm

Difficulties in aligning equations under the flalign environment

Post by Stefan Kottwitz »

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
LaTeX.org admin
vaman
Posts: 17
Joined: Wed Oct 09, 2019 5:51 am

Difficulties in aligning equations under the flalign environment

Post by vaman »

Code: Select all

\documentclass[12pt]{article}
    \begin{document}
    \begin{tabular} {p{4cm}p{6cm} r}
     
    Test : & &\\
    	
    	if	$ 4  \omega_0^2 > \gamma^2$ & $ \lambda = \frac{1}{2}  \sqrt{(4\omega_0^2 - \gamma^2)}$ & (1)\\
    	& & \\
 if $4 \omega_0^2 < \gamma^2$  &$\kappa = \frac{1}{2}\sqrt{ (\gamma^2 - 4 \omega_0^2)}$. & (2)\\
    	  & &\\
    		&EQUATION &\\
    	\end{tabular}
     
    \end{document}
Here is a simple way to do the same without any additional packages.
Post Reply