# How to align the equal signs in this equation such that the first line and last 2 lines align

so I have an equation below. My latex code for it is:

\begin{align*}
CoJPoD_{   \{I_1, \cdots, I_{k-1}, I_{k+1}, \cdots, I_{n}\} | I_{k} }  = CoJPoD_{ \{system \backslash I_{k}\} | I_k}  \\
= P\left( X_1 \ge X_d^{I_1}, \cdots, X_{k-1} \ge X_d^{I_{k-1}}, X_{k+1} \ge X_d^{I_{k+1}}, \cdots, X_n \ge X_d^{I_n} | X_k \ge X_d^{I_k}\right) \\
= \frac{    P\left( X_1 \ge X_d^{I_1}, \cdots, X_{k-1} \ge X_d^{I_{k-1}}, X_k \ge X_d^{I_k}, X_{k+1} \ge X_d^{I_{k+1}}, \cdots, X_n \ge X_d^{I_n}\right)         }{P\left(X_k \ge X_d^{I_k}\right)} \\
= \frac{JPoD_{\{I_1, I_2, \cdots, I_n\}}}{PoD_{I_k}} \\
= \frac{JPoD_{system}}{PoD_{I_k}}
\end{align*}


My question is, how do I make the equal sign in the first line, align with the equal signs in the last 2 lines so that they appear in the "middle" and align the 2 equal signs in line 2 and 3 on the far left. E.g, make it look like this: (I rearranged it in paint lol) • Welcome to TeX.sx! I added the images, and changed the code markup a little. – Torbjørn T. Apr 28 '13 at 9:06
• A tip unrelated to your question: words like “system” in the expressions look better in a text font; use \text{system} in math mode (with the amsmath library) to do that. I would also use \operatorname{JPoD} etc to format those abbreviations in text font with the proper spacing. – Matthew Leingang Apr 28 '13 at 9:49

\documentclass{amsart}
\begin{document}
\begin{align*}
&CoJPoD_{   \{I_1, \dots, I_{k-1}, I_{k+1}, \dots, I_{n}\} \mid I_{k} }  \\
&= CoJPoD_{ \{\mathrm{system} \backslash I_{k}\} \mid I_k}  \\
&= P\bigl( X_1 \ge X_d^{I_1}, \dots, X_{k-1} \ge X_d^{I_{k-1}}, X_{k+1} \ge X_d^{I_{k+1}}, \dots, X_n \ge X_d^{I_n} \mid X_k \ge X_d^{I_k}\bigr) \\
&=\frac{P\bigl( X_1 \ge X_d^{I_1}, \dots, X_{k-1} \ge X_d^{I_{k-1}}, X_k \ge X_d^{I_k}, X_{k+1} \ge X_d^{I_{k+1}}, \dots, X_n \ge X_d^{I_n}\bigr)}{P\bigl(X_k \ge X_d^{I_k}\bigr)} \\
&= \frac{JPoD_{\{I_1, I_2, \dots, I_n\}}}{PoD_{I_k}}\\
&= \frac{JPoD_{\mathrm{system}}}{PoD_{I_k}}
\end{align*}
\end{document}


Some of the changes I have made are:

• indicating how the equations should be aligned by using the & syntax.
• using \mathrm{text} for subscripts which are text of length more than 1.
• replace the \cdots directive by \dots so that amsclasses figure what is best to do.
• replace | by \mid.
• replace \left(...\right) by \bigl(...\bigr).

You'd find this entire document a very useful read. In particular, I'd like to draw you attention to the examples and discussion of the various align environments in Section 3 (pp. 3-9).

Output • Thank you! Magnificent and quick answer, exactly what I was looking for! Much appreciated. – TrueTears Apr 28 '13 at 9:15
• @TrueTears Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. – texenthusiast Apr 28 '13 at 9:23
• No need to load the amsmath package if the amsart document class is selected. I'd also (i) replace all \cdots directives with \dots (LaTeX will correctly choose the "lower dots" option...), (ii) replace | with \mid, and (iii) replace the \left( and \right) constructs with \bigl( and \bigr) directives, as the parentheses generated by the former method look a bit big and massive. – Mico Apr 28 '13 at 11:11
• @Mico I had mentioned the first one. And the others you point out are very reasonable. So, I'll edit my answer to reflect these, in a few minutes (I am just having some snack). – kan Apr 28 '13 at 11:14
• Thanks, I am new here, I upvoted the answers for the excellent suggestions by everyone. – TrueTears Apr 28 '13 at 11:30

I would still avoid the expression if possible because seemingly it's blurring the fact that the inequalities are repeated for the whole index set except k which should be easy to convey for the author and to grasp for the reader. Something along the lines of

\documentclass{article}
\usepackage{mathtools} %<- Loads amsmath and enhances/fixes it.

\begin{document}

Let us introduce the shorthand notation $\sigma_i$ for the
inequality $X_i \ge X_d^{I_i}$. Then we have,
\begin{align*}
CoJPoD_{   \{I_1, \cdots, I_{k-1}, I_{k+1}, \cdots, I_{n}\} | I_{k} }  &= CoJPoD_{ \{\text{system}\backslash I_{k}\} | I_k}\\
&= P\left( \sigma_1, \cdots, \sigma_{k-1}, \sigma_{k+1}, \cdots, \sigma_{n} | \sigma_k\right) \\
&= \frac{P\left( \sigma_{1}, \cdots, \sigma_n\right)}{P\left(\sigma_k\right)} \\
&= \frac{JPoD_{\{I_1, I_2, \cdots, I_n\}}}{PoD_{I_k}} \\
&= \frac{JPoD_{system}}{PoD_{I_k}}
\end{align*}
\end{document} Last minute edit: I've missed the fix for the second system word and the ...PoDs. But other answers covered those pretty thoroughly.

• +1 Agree! It makes the source code and the rendered output more readable. – kiss my armpit Apr 28 '13 at 20:24

And this is the solution, giving the output that you described.

\begin{align*}
CoJPoD_{   \{I_1, \cdots, I_{k-1}, I_{k+1}, \cdots, I_{n}\} | I_{k} }  &= CoJPoD_{ \{system \backslash I_{k}\} | I_k}  \\
\noalign{\text{$= P\left( X_1 \ge X_d^{I_1}, \cdots, X_{k-1} \ge X_d^{I_{k-1}}, X_{k+1} \ge X_d^{I_{k+1}}, \cdots, X_n \ge X_d^{I_n} | X_k \ge X_d^{I_k}\right)$}}\\
\noalign{\text{$= \displaystyle\frac{ P\left( X_1 \ge X_d^{I_1}, \cdots, X_{k-1} \ge X_d^{I_{k-1}}, X_k \ge X_d^{I_k}, X_{k+1} \ge X_d^{I_{k+1}}, \cdots, X_n \ge X_d^{I_n}\right) }{P\left(X_k \ge X_d^{I_k}\right)}$}} \\
& = \frac{JPoD_{\{I_1, I_2, \cdots, I_n\}}}{PoD_{I_k}} \\
& = \frac{JPoD_{system}}{PoD_{I_k}}
\end{align*} However, I'd rather like the following code:

\begin{align*}
\mathit{CoJPoD}_{   \{I_1, \ldots, I_{k-1}, I_{k+1}, \ldots, I_{n}\} | I_{k} }  &= \mathrm{CoJPoD}_{ \{\mathrm{system} \setminus I_{k}\} | I_k}  \\ %either \mathit or \mathrm
\noalign{\text{$= P\left( X_1 \ge X_d^{I_1}, \dots, X_{k-1} \ge X_d^{I_{k-1}}, X_{k+1} \ge X_d^{I_{k+1}}, \ldots, X_n \ge X_d^{I_n} | X_k \ge X_d^{I_k}\right)$}}\\
\noalign{\text{$= \displaystyle\frac{ P\left( X_1 \ge X_d^{I_1}, \ldots, X_{k-1} \ge X_d^{I_{k-1}}, X_k \ge X_d^{I_k}, X_{k+1} \ge X_d^{I_{k+1}}, \ldots, X_n \ge X_d^{I_n}\right) }{P\left(X_k \ge X_d^{I_k}\right)}$}} \\
& = \frac{\mathrm{JPoD}_{\{I_1, I_2, \cdots, I_n\}}}{\mathrm{PoD}_{I_k}} \\ %either \mathit or \mathrm
& = \frac{\mathit{JPoD}_{\mathrm{system}}}{\mathrm{PoD}_{I_k}}  %either \mathit or \mathrm
\end{align*}


Certainly, CoJPoD, JPoD, PoD should be either \mathrm or \mathit. This gives us better spacing. See also usage of \setminus instead of \backslash and \ldots instead of \cdots. • +1; I edited your post for the image (I apologise, as I could have given the link and requested that you edit it in.) – kan Apr 28 '13 at 9:44
• @kan Thank you for editing. I have still problems with proper cropping images. – Przemysław Scherwentke Apr 28 '13 at 9:47
• Why do you have some CoJPoD in upright and some in (math) italics? – Mico Apr 28 '13 at 11:13
• @Mico "Certainly, CoJPoD, JPoD, PoD should be either \mathrm or \mathit". I don't know, what they mean. I'd prefer normal shape, not italic, but I am not sure, which one OP should choose. – Przemysław Scherwentke Apr 28 '13 at 11:29
• Perfect, thanks for the suggestions regarding setminus and ldots :) – TrueTears Apr 28 '13 at 11:31

## Option 1: \documentclass[preview,border=15pt]{standalone}
\usepackage{mathtools}
\begin{document}

\begin{align*}
\mathrlap{CoJPoD_{   \{I_1, \cdots, I_{k-1}, I_{k+1}, \cdots, I_{n}\} | I_{k} }}  \\
&= CoJPoD_{ \{\mathrm{system} \backslash I_{k}\} | I_k}  \\
&= P\left( X_1 \ge X_d^{I_1}, \cdots, X_{k-1} \ge X_d^{I_{k-1}}, X_{k+1} \ge X_d^{I_{k+1}}, \cdots, X_n \ge X_d^{I_n} | X_k \ge X_d^{I_k}\right) \\
&=\frac{P\left( X_1 \ge X_d^{I_1}, \cdots, X_{k-1} \ge X_d^{I_{k-1}}, X_k \ge X_d^{I_k}, X_{k+1} \ge X_d^{I_{k+1}}, \cdots, X_n \ge X_d^{I_n}\right)}{P\left(X_k \ge X_d^{I_k}\right)} \\
&= \frac{JPoD_{\{I_1, I_2, \cdots, I_n\}}}{PoD_{I_k}}\\
&= \frac{JPoD_{\mathrm{system}}}{PoD_{I_k}}
\end{align*}

\end{document}


Here's an answer similar to that of Przemysław Scherwentke, but a little more structured. I think a question like this is a good opportunity to show off some of the things that clever people have done to make writing complex expressions simpler. First, the code:

\documentclass{article}
\usepackage{amsmath,mathtools}
\DeclareMathOperator{\Pod}{PoD}
\DeclareMathOperator{\Jpod}{JPoD}
\DeclareMathOperator{\Cojpod}{CoJPoD}
\DeclarePairedDelimiter\of{(}{)}
\DeclarePairedDelimiterX\ofx{(}{)}{#1\mathrel{\delimsize|}#2}
\newcommand*\moveback{\mkern-#1mu}
\begin{document}
\begin{align*}
\moveback{40}
\Cojpod_{\{I_1, \dots, I_{k-1}, I_{k+1}, \dots, I_n\} | I_k }
&= \Cojpod_{\{\mathrm{system} \setminus I_{k}\} | I_k}  \\
\intertext{\centering
\begin{aligned} &= P\ofx[\big]{X_1 \ge X_d^{I_1}, \dots, X_{k-1} \ge X_d^{I_{k-1}}, X_{k+1} \ge X_d^{I_{k+1}}, \dots, X_n \ge X_d^{I_n}} {X_k \ge X_d^{I_k}} \\ &= \frac{P\of[\big]{ X_1 \ge X_d^{I_1}, \dots, X_{k-1} \ge X_d^{I_{k-1}}, X_k \ge X_d^{I_k}, X_{k+1} \ge X_d^{I_{k+1}}, \dots, X_n \ge X_d^{I_n} }} {P\of{X_k \ge X_d^{I_k}}} \\ \end{aligned}
}
&= \frac{\Jpod_{\{I_1, I_2, \dots, I_n\}}}{\Pod_{I_k}} \\
&= \frac{\Jpod_{\mathrm{system}}}{\Pod_{I_k}}
\end{align*}
\end{document} This gives exactly the result you show in the question and not the result produced by the answers of Bugbusters or kan. I actually think your picture is better than the one in their answers, because the second and third lines are just too long to be placed in alignment with the others. Here is a commentary on what I did, aside from some of the changes that others have pointed out:

• The mess of \DeclareMathOperators in the preamble sets up correctly-formatted structured operators: it sets PoD, JPoD, and CoJPoD in roman, gives them the proper spacing from their arguments and subscripts, and also alleviates the tedium of getting the capitalization right. This is from amsmath.

• Likewise, \DeclarePairedDelimiter(X), which comes from mathtools, sets up the parentheses of your various P(...) expressions. The second one writes what I assume is a conditional probability so that the vertical bar is correctly sized and spaced (this kind of thing is exactly what this construction was designed to help with).

• I also wrote a simple \moveback macro that transparently wraps a negative space (given in units of mu, which is 1/18 of a \quad space) and allows you to move the long first line left, which probably improves the appearance of the "centered" bit of the display. The number 40 I chose for its argument was basically eyeballed.

• In the equations, I put the unaligned material in an \intertext rather than \noalign, simply for the reason that this is a more sophisticated macro built on the latter, primitive command, and is designed to work (in some fashion I don't totally know the internals of) with the amsmath environments.

• Inside the \intertext, I put the actual math inside a aligned envrionment in regular \$ math. There seems to be some kind of issue using a straight-up align* within \intertext, or even \noalign.

• The \intertext also contains a \centering directive, which addresses the following bug of the style you describe: if the page is very wide, then the second and third lines will still be flush left and therefore look quite terrible. Centering them puts them in the same column as the first and last two.

• Is \! needed before \begin{aligned} in this case? – kiss my armpit Apr 28 '13 at 19:50
• Oh, that thing. Yes, it does seem to make a difference. – Ryan Reich Apr 28 '13 at 20:33