# Aligned Environment Not Aligning a Single Operator

So, I'm typesetting a solution to a Quiz I gave, and the aligned environment (inside of my equation environment) is giving me an incorrect alignment on only one of my operators. Here's the batch of code I'm concerned with:

\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
\begin{aligned}
x=-2 &\Rightarrow \frac{-2+1}{-2-4} &= \frac{-1}{-6} &= \frac{1}{6} &> 0 \\
x=0 &\Rightarrow \frac{0+1}{0-4} &= \frac{1}{-4} &= -\frac{1}{4} &< 0 \\
x=5 &\Rightarrow \frac{5+1}{5-4} &= \frac{6}{1} &= 6 &> 0
\end{aligned}
\end{equation*}

\end{document}


When I run this to create my pdf, the equals sign in the final row in front of 6/1 appears to the right of the two above it. Any ideas on how to fix this, or why it's happening?

-
I think that the aligned environment understands your code in a different way than what you thought. Here it understands that the first & symbol is meant to align binary symbols while the second & is here to delimit two equations on the same line (see this article for an example, section "Multiple equations on one line"). However I have no idea about how to fix this. Even numbered & delimits different equations and odd numbered & help aligning binary operators. – Ludovic C. Sep 26 '13 at 15:54
Thank you for this comment! I thought that the ampersands were used in an either/or fashion, not as a specific order of binary symbol alignment and equation delimiter. I'll be sure to remember this in the future! – Raeil Sep 27 '13 at 14:03

## 2 Answers

The aligned environment alternates right/left alignment between columns, so you need a few double & characters to change the alignment to the desired form. If I understand your desire, it may be as follows (or maybe not):

\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
\begin{aligned}
x=-2 &\Rightarrow \frac{-2+1}{-2-4} &&= \frac{-1}{-6} &&= \frac{1}{6} &> 0 \\
x=0 &\Rightarrow \frac{0+1}{0-4} &&= \frac{1}{-4} &&= -\frac{1}{4} &< 0 \\
x=5 &\Rightarrow \frac{5+1}{5-4} &&= \frac{6}{1} &&= 6 &> 0
\end{aligned}
\end{equation*}

\end{document}

-
Also consider alignat that provides a regular-sized space between relations in this case. – Werner Sep 26 '13 at 16:04
This is definitely what I was looking for! It doesn't quite align the columns, but I wanted the relations to be aligned as perfectly as possible. Thank you! – Raeil Sep 27 '13 at 14:09

The alignment points for aligned alternate right/left/right/left/... You can notice this effect also with the alignment of the first = signs in each line. It is also assumed that each right/left pair is independent, which is why there is a larger space between segments in two places.

Since not all cells of this expression contain minus signs, they will never all be the same width.

If you want all the relations to be aligned, you should use alignedat instead of aligned, which will get rid of the extra space between "pairs". (this requires an additional condition, namely the number of "columns", in braces after the \begin{alignedat})

Then you can double the & in front of the "unaligned" relation signs to line them up. Since alignedat then doesn't honour the usual spacing around relations, you should insert {} before the affected signs on the first line (the other lines will then align with the first).

I've indulged in overkill in this example, inserting a phantom to align the elements with "missing" minus signs.

\documentclass[12pt]{article}
\usepackage{amsmath}

\newcommand{\0}{\phantom{-}}
\begin{document}

\begin{equation*}
\begin{alignedat}{5}
x&=-2 &{}\Rightarrow \frac{-2+1}{-2-4} &&{}= \frac{-1}{-6} &&{}= \0\frac{1}{6} &&{}> 0 \\
x&= \0 0 &\Rightarrow \0\frac{0+1}{0-4} &&= \frac{1}{-4} &&= -\frac{1}{4} &&< 0 \\
x&= \0 5 &\Rightarrow \0\frac{5+1}{5-4} &&= \0\frac{6}{1} &&= \0 6 &&> 0
\end{alignedat}
\end{equation*}

\end{document}


(I'm not sure why the last = on the last line isn't properly aligned; I'll have to look into that.)

-
I noticed the phantom command when I was looking for a solution before posting my question. I think I'll need to look into that further for future use on exams/quizzes. Also I've got a (slightly unrelated) question. I was trying to add the image of what the code produced, but couldn't quite figure out how to do so. How did you make it appear below the code block? – Raeil Sep 27 '13 at 14:11
@Raeil -- adding an image is quite easy, but it requires a certain amount of rep, which you didn't have yet. to add an image, click on the rectangular blue icon to the right of the { } icon in the icon bar; this will give you options for uploading an image (i use "browse" to get it directly from my workstation). even if you don't have enough rep, you can specify the image (it has to be a .png file) -- just remove the ! in front of the reference, and someone who does have enough rep will notice, and activate it. – barbara beeton Sep 27 '13 at 15:50
@barbarabeeton nice answer. thanks for including an image. I noticed your comment about the last line = not being aligned, but i think the problem is that it's still within an environment, so it needs to be treated as such. eg. \0\frac{}{}6 – doed Sep 27 '13 at 20:05
@LudovicC -- i'll tolerate the uppercasing (please see the last paragraph of my profile regarding why i use lowercase), and appreciate accurate spelling corrections, but please don't change my spelling to british ("honor" to "honour"). i'd like to ask you politely to fix that. – barbara beeton Sep 28 '13 at 12:20
@barbarabeeton Sorry for the british-english exchange. Realised that when seeing your comment, and it is noted for the lowercase answers. – Ludovic C. Sep 28 '13 at 12:25