LaTeX forum ⇒ Math & ScienceSmall alignment problem in two equations Topic is solved

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

Small alignment problem in two equations  Topic is solved

Postby Cham » Fri Jul 29, 2016 5:47 pm

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

  1. \documentclass[12pt,letterpaper]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{amsmath}
  4.  
  5. \begin{document}
  6.  
  7. \begin{align}
  8. 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]
  9. 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).
  10. \end{align}
  11.  
  12. \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 3320 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:

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

Postby Stefan Kottwitz » Fri Jul 29, 2016 6:11 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
  1. alignat
environment of amsmath. Here it's applied:

  1. \documentclass[12pt,letterpaper]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{amsmath}
  4. \begin{document}
  5. \begin{alignat}{3}
  6. 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]
  7. 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).
  8. \end{alignat}
  9. \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
Site admin

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

Postby Stefan Kottwitz » Fri Jul 29, 2016 6:43 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
Site admin

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

Postby Cham » Fri Jul 29, 2016 7:03 pm

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: 9445
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Fri Jul 29, 2016 7:06 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
Site admin

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

Postby Cham » Fri Jul 29, 2016 7:09 pm

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

  1. \documentclass[12pt,letterpaper]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{amsmath}
  4.  
  5. \begin{document}
  6.  
  7. \begin{alignat}{4}
  8. 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]
  9. 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).
  10. \end{alignat}
  11.  
  12. \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 3308 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: 9445
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Fri Jul 29, 2016 7:22 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
Site admin

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

Postby Cham » Fri Jul 29, 2016 7:25 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.


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 4 guests