Math & ScienceAlignment Problem with System of 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

Alignment Problem with System of Equations

Post by Cham »

I have a small alignment problem with the following compilable code :

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\begin{document}
  \begin{align*}
    A &= B \\ \\
      &= C = D \\ \\
      &= E = F,
  \end{align*}
\end{document}
I need the "E" item to be aligned with the "D" item. Currently, it's aligned with the "C" item, which isn't good. How can I fix it ?

I'm sure that the solution should be trivial, but I really don't see it ! :oops: Using "&&" doesn't do it.

EDIT : I should probably use the alignat command, but it doesn't work right now...

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alignment Problem with System of Equations

Post by localghost »

Cham wrote:[…] I should probably use the alignat command, but it doesn't work right now...
Add a minimal example to your inadequate problem description and explain exactly what does not work. At the moment problems with the alignat environment are incomprehensible.


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

Re: Alignment Problem with System of Equations

Post by Cham »

I already gave a minimal compilable example. I don't know how to use the alignat command so I can't give a proper compilable example with it.

My question is still the same : How can I align the "D" and "E" in the code I gave above ?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alignment Problem with System of Equations

Post by localghost »

Cham wrote:[…] I don't know how to use the alignat command so I can't give a proper compilable example with it. […]
A proper minimal example shall reproduce errors or misbehaviour. That's something you should know by now. Your example doesn't use the alignat environment at all and compiles flawlessly, thus does not give a clue what you are doing wrong. Submit an example that shows your own efforts with the alignat environment. We are not here to present a solution from scratch. It will need a bit of own initiative.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Alignment Problem with System of Equations

Post by Cham »

My question is not about what I'm doing wrong. My question is about how to do something I don't know how to ! How can I modify my code above so the "E" and "D" are aligned ?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alignment Problem with System of Equations

Post by localghost »

I suggest to take look at the explanations to the alignat environment that are given in the amsmath manual. I couldn't do it better. But I think the excellent »Math mode« document will also help you on this regard. Both documents should show you the necessary modifications to your code.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Alignment Problem with System of Equations

Post by Cham »

The docs doesn't help much. Here's a compilable code :

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\begin{document}
	\begin{align*}
		A &= Bxy - 3 \\ \\
		&= Cz^2 + bc = Dx - 4 \\ \\
		&= Ex + yz = F,
	\end{align*}

	\begin{alignat*}{2}
		A &= Bxzy - ce \\ \\
		&= C &&= D \\ \\
		& &&= E = F,
	\end{alignat*}
\end{document}
In the case of the alignat part, the "E" and "D" are properly aligned, but there's an annoying extra space after the "C". How can I modify this code to remove the extra space ?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alignment Problem with System of Equations

Post by localghost »

The mathtools package has some useful additions to amsmath. One of them is the \mathrlap command.

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}   % loads »amsmath«

\begin{document}
  \begin{alignat*}{3}
    A &=\mathrlap{Bxzy-ce} \\
      &= C &&= D           \\
      &    &&= E &&= F,
  \end{alignat*}
\end{document}
The package manual has the details. Other useful tips can be found in the document I mentioned earlier.

Your final example has been very helpful on the way to a solution.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Alignment Problem with System of Equations

Post by Cham »

Hmm, it wasn't so trivial, after all.

Thanks.
Post Reply