# Fix indentation in align* environment

The first two lines have fewer characters than the second two in the the align* environment, they are flushed right and seem awkwardly out of alignment with the last two equations. (Note that the only reason I have an additional space in front within the text command in the last two equations like \text{ if...} and not \text{if...} like the first two is just from a (failed) attempt at fixing the spacing).

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\ldots-\frac{1}{x^2+1} & \text{if $n$ is odd and is } 1,5,9,13,\ldots\\
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\ldots+\frac{1}{x^2+1} & \text{if $n$ is odd and is } 3,7,11,15,\ldots\\
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\ldots-\frac{x}{x^2+1} & \text{ if $n$ is even and is } 2,6,10,14,\ldots\\
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\ldots+\frac{x}{x^2+1} & \text{ if $n$ is even and is } 4,8,12,16,\ldots
\end{align*}
\end{document}


which outputs:

I have ways to sooth this (like just saying n=4k+1, 4k+2, etc. or just specifying the conditions elsewhere before or after the equations), but for future reference, what would be a nice way to fix this inside of the align* environment? I think it would just look better if things were aligned to the left in the second part of the lines. Is there any best practice for something like this?

Also, I am aware of the cases and dcases environments and whatnot (which is what I finally used), but am seeking answers for this environment specifically.

align (and its starred version align* aligns content using a Right & Left approach around the alignment character &. Multiple alignments follow the same approach, separated by a single &. The following minimal example highlights this:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
R1 & L1 & R2 & L2 & R3 & L3 & R4 & L4 \\
R1&L1  &  R2&L2  &  R3&L3  &  R4&L4
\end{align*}

\end{document}


The first line shows a bunch of Right and Left alignments, separated by alignment markers &. The second line has the pseudocode mimicing the alignment, for clarity.

With the above information, you want the left construction around the = to be aligned like R1&L1, while you want the textual description to be aligned to the Left only (without a Right counterpart) and therefore would use &&L2:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
% Alignment: R1&L1 & &L2
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\dots-\frac{1}{x^2+1} && \text{if $n$ is odd and is $1,5,9,13,\dots$} \\
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\dots+\frac{1}{x^2+1} && \text{if $n$ is odd and is $3,7,11,15,\dots$} \\
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\dots-\frac{x}{x^2+1} && \text{if $n$ is even and is $2,6,10,14,\dots$} \\
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\dots+\frac{x}{x^2+1} && \text{if $n$ is even and is $4,8,12,16,\dots$}
\end{align*}

\end{document}


Note the use of \dots, which automatically switches to \cdots within a binary operator sequence, and \ldots within a series.

Environment align* is intended for equation systems with right and left aligned parts. The example is fixed by using && instead of & to get \text{if...} left aligned:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\ldots-\frac{1}{x^2+1} && \text{if $n$ is odd and is } 1,5,9,13,\ldots\\
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\ldots+\frac{1}{x^2+1} && \text{if $n$ is odd and is } 3,7,11,15,\ldots\\
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\ldots-\frac{x}{x^2+1} && \text{if $n$ is even and is } 2,6,10,14,\ldots\\
\frac{x^{n+1}}{x^2+1} &= x^{n-1}-x^{n-3}+x^{n-5}-\ldots+\frac{x}{x^2+1} && \text{if $n$ is even and is } 4,8,12,16,\ldots
\end{align*}
\end{document}