# Aligning long Equations

How could I align the expression [F_{1}(M)\cdot L_{M+1}]_{ij} with the rest of the equations? This is the code I am using:

\begin{align*}
[F_{1}(M)\cdot L_{M+1}]_{ij} \\
&=\sum_{s=1}^{\infty}\prob(\gamma(M+1)<\gamma(0),\phi(\gamma(M+1))=s|X(0)=1,\phi(0)=i)\cdot\\
&\prob(\gamma(M+2)<\gamma(0),\phi(\gamma(M+2))=j|X(0)=M+1,\phi(0)=s)\\
&=\sum_{s=1}^{\infty}\prob(\gamma(M+2)<\gamma(0),\phi(\gamma(M+1))=s,\phi(\gamma(M+2))=j|X(0)=1,\phi(0)=i)\\
&= \prob(\gamma(M+2)<\gamma(0),\phi(\gamma(M+2))=j|X(0)=1,\phi(0)=i) = [F_{1}(M+1)]_{ij}
\end{align*}


The output is like in the attached image.

I'd use something like this

Note I changed your conditional |'s to \mid's to give them better spacing. The normal | kinda drowns

Edit: Missed the \cdot, this is exactly why one never ends a displayed line with a relation or a binary, it gets overlooked.

\documentclass[a4paper]{article}
\usepackage{mathtools,amssymb}
\newcommand\prob{\mathbb{P}}
\begin{document}
\begin{align*}
\MoveEqLeft[3] [F_{1}(M)\cdot L_{M+1}]_{ij}
\\
= {} &\sum_{s=1}^{\infty}\prob(\gamma(M+1)<\gamma(0),\phi(\gamma(M+1))=s\mid X(0)=1,\phi(0)=i)
\\
& \cdot  \prob(\gamma(M+2)<\gamma(0),\phi(\gamma(M+2))=j\mid X(0)=M+1,\phi(0)=s)
\\
= {} &\sum_{s=1}^{\infty}\prob(\gamma(M+2)<\gamma(0),\phi(\gamma(M+1))=s,\phi(\gamma(M+2))=j \mid X(0)=1,\phi(0)=i)
\\
= {} & \prob(\gamma(M+2)<\gamma(0),\phi(\gamma(M+2))=j\mid X(0)=1,\phi(0)=i) = [F_{1}(M+1)]_{ij}
\end{align*}
\end{document}

• I think the third row needs to be right-indented relative to the second row.
– Mico
Commented Sep 27, 2023 at 13:29
• @Mico Might be I missed the \cdot which should of course never be at the end of a line Commented Sep 27, 2023 at 13:38
• +1. I've taken the liberty of adding a screenshot to accompany the code; feel free to revert.
– Mico
Commented Sep 27, 2023 at 13:45

Here's my suggestion.

Observe that I've replaced all four instances of | with \bigm\vert and manually increased the sizes of the opening and closing parentheses in each line. I'd also place the final term, i.e., [F_{1}(M+1)]^{}_{ij}, on a new row.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb}
\DeclareMathOperator{\prob}{\mathbb{P}}

\begin{document}

\begin{align*}
&[F_{1}(M)\cdot L_{M+1}]^{}_{ij} \\
&= \sum_{s=1}^{\infty} \prob\bigl( \gamma(M+1)<\gamma(0),\phi(\gamma(M+1))=s
\bigm\vert X(0)=1,\phi(0)=i\bigr)\\
\bigm\vert X(0)=M+1,\phi(0)=s \bigr) \\
&= \sum_{s=1}^{\infty} \prob\bigl(  \gamma(M+2)<\gamma(0),
\phi(\gamma(M+1))=s, \phi(\gamma(M+2))=j
\bigm\vert X(0)=1,\phi(0)=i \bigr) \\
&= \prob\bigl( \gamma(M+2)<\gamma(0),\phi(\gamma(M+2))=j
\bigm\vert X(0)=1,\phi(0)=i \bigr) \\[\jot]
&= [F_{1}(M+1)]^{}_{ij}
\end{align*}

\end{document}


My advice is as follows. It's improved from @Mico 's solution:

1. add the indentation by \hptantom of the first line of the equations;
2. add the indentation by \hptantom of the third line of the equations;
3. use \left and \right instead of \bigl and \bigr before parenthesis;
4. use \mid instead of \bigm\vert;
5. delete [\jot] codes of the sixth line of the equations;
6. add the dot . at the end of the last line of equations.

Welcome others to improve the current solution furthermore.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb}
\DeclareMathOperator{\prob}{\mathbb{P}}

\begin{document}

\begin{align*}
&\hphantom{=~}[F_{1}(M)\cdot L_{M+1}]^{}_{ij} \\
&= \sum_{s=1}^{\infty} \prob\left(\gamma(M+1)<\gamma(0),\phi(\gamma(M+1))=s
\mid X(0)=1,\phi(0)=i\right)\\
&\hphantom{=\sum_{s=1}^{\infty}}\times \prob\left(\gamma(M+2)<\gamma(0),\phi(\gamma(M+2))=j
\mid X(0)=M+1,\phi(0)=s \right) \\
&= \sum_{s=1}^{\infty} \prob\left(\gamma(M+2)<\gamma(0),
\phi(\gamma(M+1))=s, \phi(\gamma(M+2))=j
\mid X(0)=1,\phi(0)=i \right) \\
&= \prob\left(\gamma(M+2)<\gamma(0),\phi(\gamma(M+2))=j
\mid X(0)=1,\phi(0)=i \right) \\
&= [F_{1}(M+1)]^{}_{ij}.
\end{align*}

\end{document}


• I think it might be useful if you stated explicitly what the "improvements" are... :-)
– Mico
Commented Sep 27, 2023 at 14:21
• @Mico I revised the statements. Commented Sep 28, 2023 at 0:08
• Thanks. I'd question whether #3 is an improvement, as the \left and \right directives don't do anything useful: The associated parentheses are at the basic size (hence: why bother with the \left and \right directives?), while the spacing between \prob and the opening parentheses is now messed up. There normally shouldn't be a space between math-op and math-open objects; cf. \sin(\alpha) and \log(2). #4 is a measure to stay consistent with #3. #5 is an aesthetic choice, and one shouldn't argue about tastes, right? Same for #1. #6 appears to be a deviation from the OP's setup.
– Mico
Commented Sep 28, 2023 at 2:44