Math & ScienceAlign equations with multiple align points

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
kingliam
Posts: 5
Joined: Wed Jan 22, 2025 7:22 pm

Align equations with multiple align points

Post by kingliam »

I am just starting to learn LaTeX, and am having some struggles aligning math equations. This is for writing up my homework solutions, so I would like to have multiple lines of math, with multiple alignment points. For example, in the following scenario, I would like the = after b to be aligned with = after e, as well as = before h to be aligned with = before i. (Ignore underscore, only there to align the text how I would like it).

a + b = c + d
___e = f + g = h
___________= i + j

Please let me know the best way to do this. Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
Bartman
Posts: 364
Joined: Fri Jan 03, 2020 2:39 pm

Re: Align equations with multiple align points

Post by Bartman »

Check out the alignat environment in the amsmath user's guide.
kingliam
Posts: 5
Joined: Wed Jan 22, 2025 7:22 pm

Re: Align equations with multiple align points

Post by kingliam »

Thank you. This was helpful. I am now having an issue where if one of the equations is too long, it will correspondingly shift the alignment to the right, and it looks very awkward. Here is an example of what I mean: https://www.overleaf.com/read/ntrzwbgzgtkf#0b5327
Any suggestions?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10281
Joined: Mon Mar 10, 2008 9:44 pm

Re: Align equations with multiple align points

Post by Stefan Kottwitz »

That's because of the alignment of the whole structure; if one row has a longer entry, the other rows must align.

You can create nested structures using the "aligned" environment inside alignat. Or smash the width of some pieces like this, as a quick way:

Code: Select all

\documentclass{article}
\usepackage{amsmath,mathtools}
\begin{document}
\begin{alignat*}{2}
  a &= \mathrlap{b + c + d + e + f} \\
  g &= h + i &&= j \\
            &&&= \mathrlap{k + l + m}
\end{alignat*}
\end{document}
Stefan
LaTeX.org admin
kingliam
Posts: 5
Joined: Wed Jan 22, 2025 7:22 pm

Re: Align equations with multiple align points

Post by kingliam »

Thank you!! This is exactly what I needed :)
Post Reply