1
$\begingroup$

Recently I had answered a question.

enter image description here

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?

$\endgroup$
3
  • 2
    $\begingroup$ 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. $\endgroup$
    – hardmath
    Jun 19, 2020 at 4:10
  • 1
    $\begingroup$ Ok! I'm using mobile site. It might be because of that as the features are optimized on mobile site. $\endgroup$
    – SarGe
    Jun 19, 2020 at 4:40
  • 4
    $\begingroup$ 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. $\endgroup$
    – Xander Henderson Mod
    Jun 19, 2020 at 5:15

1 Answer 1

5
$\begingroup$

StackExchange has automatic line breaking turned on so that long expressions are broken, when possible. For mobile devices, the width is small, and so this can occur more often than on desktop computers. MathJax tries to avoid breaking within parentheses, and so the "natural" breakpoint is at the equal sign. That is what you are seeing, here, with the equal sign on one line and the limit on another.

$\endgroup$
7
  • $\begingroup$ 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.) $\endgroup$
    – user1729
    Jun 21, 2020 at 18:55
  • $\begingroup$ 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. $\endgroup$ Jun 22, 2020 at 12:39
  • $\begingroup$ Thanks, I never knew that! (I knew that LaTeX doesn't require, or indeed like, dollars around the align environment, but I've always assumed that MathJax needs dollars around all the maths, even fancy environments. I don't know why I though that.) $\endgroup$
    – user1729
    Jun 22, 2020 at 16:00
  • $\begingroup$ If I recall correctly, that was true of the very earliest versions of MathJax, but hasn't been in some time. Probably not since v2.0.0 $\endgroup$ Jun 22, 2020 at 16:49
  • $\begingroup$ That makes sense then. I seem to have been using it since before that release, and my knowledge had not been updated at the same rate as MathJax. $\endgroup$
    – user1729
    Jun 22, 2020 at 16:55
  • $\begingroup$ @Davide Cervone, using {align*} can make the equations perfectly aligned, right? $\endgroup$
    – SarGe
    Jun 22, 2020 at 17:57
  • 1
    $\begingroup$ @doubtnut, the star does not change the alignment of the equation. In AMS document in LaTeX, alignments and other top-level tabular math environments produce equations with automatically generated equation numbers. The starred form produces the same alignment without those automatic numbers. In MathJax, automatic numbering is off by default (for historical reasons), but can be activated in the MathJax configuration. So by default the starred and unstarred versions should be the same. $\endgroup$ Jun 22, 2020 at 18:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .