# $\rm\LaTeX$ align code is not working properly.

I had used the $$\rm\LaTeX$$ command \begin{align}...\end{align} but the equations are not perfectly aligned. This is the code I used

\begin{align} f(x)&=\lim_{n\to\infty} \frac{ax} {n}\left(\sum_{k=1}^n \frac{[k^2-e^{-x}+k-1]}{k(k+1)}\right)+\lambda\\ &=\lim_{n\to\infty} \frac{ax}{n}\left(\sum_{k=1}^n \frac{k^2+k-2}{k(k+1)}\right)+\lambda\\ &=\lim_{n\to\infty} \frac{ax}{n}\left(\sum_{k=1}^n 1-2\left(\frac{1}{k}-\frac{1}{k+1}\right)\right)+\lambda\\ &=\lim_{n\to\infty} \frac{ax}{n}\left(n+\frac{1}{n+1}-2\right)+\lambda\\ &=ax+\lambda \end{align}


What's wrong with the code? Or how can I fix it so that the equations are properly aligned?

• When I view the linked Answer on the main site, the equations appear properly aligned. I use Chromium on Linux (Fedora 31), and my Math Settings are Math Renderer HTML+CSS with Fast Preview enabled. – hardmath Jun 19 '20 at 4:10
• Ok! I'm using mobile site. It might be because of that as the features are optimized on mobile site. – SarGe Jun 19 '20 at 4:40
• I don't know what is causing the problem, but there are two potential issues: (1) you put the align environment into an inline math environment. Don't do this. MathJax detects \begin{align} and \end{align} all on its own; you don't need (or want) to put this environment into another math environment; (2) it is possible that the "responsive design" is causing problems---phone screens are quite narrow, and it may be that your lines are too long to render nicely on a phone screen. – Xander Henderson Jun 19 '20 at 5:15

• Does using one dollar versus two make a difference here? In particular, I notice that the new lines start in the middle of the line, so would this change if the number of dollars used was changed? (Xander Henderson's comment to the original post made me wonder about this, and if we should indeed care about the number of dollars used with \align.) – user1729 Jun 21 '20 at 18:55
• No, when line breaking is enabled, both in-line (single dollar) and displayed math (double dollar and \begin{...}) will cause line breaking to occur when the math is wider than the container width. You should not enclose \begin{align}...\end{align} in dollar signs of any type, as they represent an AMS math environment that is intended to be a top-level math container. MathJax doesn't prevent you from putting them in dollar signs, but that would cause an error in actual LaTeX. – Davide Cervone Jun 22 '20 at 12:39
• @Davide Cervone, using {align*} can make the equations perfectly aligned, right? – SarGe Jun 22 '20 at 17:57