## LaTeX forum ⇒ Math & Science ⇒ Small alignment problem in two equations Topic is solved

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

### Small alignment problem in two equations  Topic is solved

I'm having difficulties in aligning some parts in the two equations below :

\documentclass[12pt,letterpaper]{article}\usepackage[T1]{fontenc}\usepackage{amsmath} \begin{document} 	\begin{align}		ds^2 &= dt^2 - \ell_{\Lambda}^2 \sinh^2 {\omega t} \, \big( \, d\chi^2 + \sinh^2 {\chi} \; (\, d\vartheta^2 + \sin^2 {\vartheta} \; d\varphi^2 ) \big), \\[18pt]		ds^2 &= dt^2 - \ell_{\Lambda}^2 \cosh^2 {\omega t} \, \big( \, d\chi^2 + \sin^2 {\chi} \; (\, d\vartheta^2 + \sin^2 {\vartheta} \; d\varphi^2 ) \big).	\end{align} \end{document}

I need the angular parts ($d\vartheta^2 + \sin^2 \vartheta \; d\varphi^2$ **) to be perfectly aligned, for aesthetical reasons only. Of course, the alignment problem is caused by the hyperbolic functions which don't have exactly the same number of letters (and same letters shape) as the trigonometric functions.

Here's a preview of what the code above is doing, and the problem indicated in red :
alignment.jpg (16.6 KiB) Viewed 3720 times

So how should I achieve the alignment I'm looking for ?

** Why on Earth can't I use simple LaTeX commands on a LaTeX board here !? The LaTeX symbols should be displayed correctly, instead of showing the commands !

EDIT : Inserting the command \phantom{h} inside the second equation doesn't do the trick very well, since it gives an exagerated visible space after the sin^2 {\chi} function. I tried adding \, and \; here and there, but the result isn't satisfying (too approximate).

I guess the solution is to center the \sin^2 {\chi} by adding more space at its left and at its right, to balance the \sinh^2 {\chi} above it.

Tags:

Stefan Kottwitz
Posts: 9568
Joined: Mon Mar 10, 2008 9:44 pm
Hi Cham,

you provided an excellent minimal example! And even better, an additional screenshot, great! That makes fun here.

You can easily align formulas at several places using the
alignat
environment of amsmath. Here it's applied:

\documentclass[12pt,letterpaper]{article}\usepackage[T1]{fontenc}\usepackage{amsmath}\begin{document}         \begin{alignat}{3}                 ds^2 &= dt^2 - \ell_{\Lambda}^2 \sinh^2 {\omega t} \, &&\big( \, d\chi^2 + \sinh^2 {\chi} \; &&( d\vartheta^2 + \sin^2 {\vartheta} \; d\varphi^2 ) \big), \\[18pt]                 ds^2 &= dt^2 - \ell_{\Lambda}^2 \cosh^2 {\omega t} \, &&\big( \, d\chi^2 + \sin^2 {\chi} \; &&( d\vartheta^2 + \sin^2 {\vartheta} \; d\varphi^2 ) \big).         \end{alignat}\end{document}

Note, the argument 3 means three align blocks (left-right blocks). The && specify the alignment points. Actually, one & is for aligning in the block, one & is for separating blocks such as in array or tabular. Overloaded use... but I thing it's easy to use: && at each additional alignment position, the argument number (3 here) for the number of all alignment points (including the first & used as in the original align).

Stefan

Stefan Kottwitz
Posts: 9568
Joined: Mon Mar 10, 2008 9:44 pm
Cham wrote:Why on Earth can't I use simple LaTeX commands on a LaTeX board here !? The LaTeX symbols should be displayed correctly, instead of showing the commands !

We are not a math forum that displays actual formulas using LaTeX commands for output.

We are a LaTeX forum and speak about LaTeX commands, so we display the commands as they are while we speak. That's the simple reason.

To display output, we use screenshots, that show the actual issue instead of some rendering by some latex module which doesn't need to match the output of real LaTeX. Or which could break anyway when it comes to more complex formulas, using packages, or non-default fonts.

Stefan

Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm

The problem with it, is that the extra space in the second equation feels exagerated. I would prefer to center the \sin^2 {\chi} below the similar \sinh^2 {\chi} above it, with smaller extra spaces on left and on right. How can we do this, so the next parenthesis are exactly aligned ? ?

Stefan Kottwitz
Posts: 9568
Joined: Mon Mar 10, 2008 9:44 pm
You could keep alignat for ensuring the alignment, and move or center the shorter thing a bit, such as by inserting \, before and after.

Stefan

Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm
Ok, I think this is a very good compromise. Your trick works very well :

\documentclass[12pt,letterpaper]{article}\usepackage[T1]{fontenc}\usepackage{amsmath} \begin{document} 	\begin{alignat}{4}		ds^2 &= dt^2 - \ell_{\Lambda}^2 \sinh^2 {\omega t} \, &&\big( \, d\chi^2 + \sinh^2 {\chi} \; &&&(\, d\vartheta^2 + \sin^2 {\vartheta} \; d\varphi^2 ) \big), \\[18pt]		ds^2 &= dt^2 - \ell_{\Lambda}^2 \cosh^2 {\omega t} \, &&\big( \, d\chi^2 + \; \sin^2 {\chi} \; &&&(\, d\vartheta^2 + \sin^2 {\vartheta} \; d\varphi^2 ) \big).	\end{alignat} \end{document}

EDIT : Here's a view of my final equations (with a zoom to see the details). I think this is as good as it can be.
alignat4.jpg (29.92 KiB) Viewed 3708 times

Just for the fun, anyone here recognize what these equations are ?
Last edited by Cham on Fri Jul 29, 2016 7:22 pm, edited 1 time in total.

Stefan Kottwitz
Posts: 9568
Joined: Mon Mar 10, 2008 9:44 pm
Very good! You might consider using an upright d for the differential operators, as operators are usually upright such as the trigonometric operators, to not see it like variable d. But it depends on taste too, one might not like a mix of upright and italic.

Stefan

Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm
Stefan_K wrote:Very good! You might consider using an upright d for the differential operators, as operators are usually upright such as the trigonometric operators, to not see it like variable d. But it depends on taste too, one might not like a mix of upright and italic.

I don't like upright "d" for the differentials. I use bold upright "d" for the "forms", though :

dx = 1-form

dx = same thing, or interpreted as an "infinitesimal number" (from non-standard analysis).

Also, dx^2 is actually a short notation for dx \otimes dx.