Math & ScienceSmall alignment problem in two equations

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

Small alignment problem in two equations

Post by Cham »

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

Code: Select all

\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
alignment.jpg (16.6 KiB) Viewed 13887 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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Small alignment problem in two equations

Post by Stefan Kottwitz »

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:

Code: Select all

\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
LaTeX.org admin
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Small alignment problem in two equations

Post by Stefan Kottwitz »

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
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Small alignment problem in two equations

Post by Cham »

Thanks for the answer, Stefan.

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 ? ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Small alignment problem in two equations

Post by Stefan Kottwitz »

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
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Small alignment problem in two equations

Post by Cham »

Ok, I think this is a very good compromise. Your trick works very well :

Code: Select all

\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
alignat4.jpg (29.92 KiB) Viewed 13875 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.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Re: Small alignment problem in two equations

Post by Stefan Kottwitz »

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
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Small alignment problem in two equations

Post by Cham »

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

Small alignment problem in two equations

Post by vaman »

Code: Select all

\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}
%This will be equation. I added after + sign \;. It looks satisfactory.[code/][code]
Last edited by vaman on Tue Sep 07, 2021 4:37 am, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Small alignment problem in two equations

Post by Stefan Kottwitz »

We had a proper solution 5 years ago: using the alignat environment for aligning at several places in equations. The post by varman should be ignored since it's just manual re-positioning until it looks somehow satisfactory.

Stefan
LaTeX.org admin
Post Reply