[Tex/LaTex] how can I align limits at “lim”

alignmath-operators

I am trying to align several limit expressions at varying x-values. It seems that align treats the "limit" portion together with its subscript as an entire object, then aligns these limits, which produces expressions aligned at "x" rather than "lim":

\documentclass[reqno,12pt]{article}
\usepackage{amsmath,amssymb,amsthm}
\addtolength{\jot}{3em}

\begin{document}

\begin{flalign*}
    &\lim_{x \to -2} x =&\\
    &\lim_{x \to -1} x =&\\
    &\lim_{\phantom{-}x \to 0} x =&\\
    &\lim_{\phantom{-}x \to 1} x =&\\
    &\lim_{\phantom{-}x \to 2} x =&\\
    &\lim_{\phantom{-}x \to \infty} x =&\\
    &\lim_{x \to -\infty} x =&
\end{flalign*}
\end{document}

I've tried to place the align marker in other places, and also fudge it using phantoms, (which isn't nice but much better than without). Is there a way around this so that each expression aligns at "l" in "lim"?

enter image description here

Best Answer

Many thanks for posting a full MWE.

Rather than redefine \lim directly to handle your special alignment objective, it is preferable to define a new command called, say, \mylim. Modifying directly the ways that LaTeX use to place the argument of a "math operator" such as \lim may end up breaking all kinds of things...

The \mylim macro defined below takes two arguments: the item that the limit is taken over, and the subscript argument of \lim. Note that the arguments are encased in curly braces -- no subscript symbol is used. In the example code below, the outer array environment and the vertical bar are used merely to illustrate that "lim" and the subscript argument are both aligned flush-left.

enter image description here

\documentclass[12pt]{article}
\newcommand\mylim[2]{%
    \begin{array}[t]{@{}l@{}}
     \lim #1 \\[-1ex] \scriptstyle #2 
    \end{array}
}
\begin{document}
\[ \begin{array}{|@{}l}
     \mylim{x}{x \to -2}  =\\
     \mylim{x}{x \to -1}  =\\
     \mylim{x}{x \to 0}  =\\
     \mylim{x}{x \to 1}  =\\
     \mylim{x}{x \to 2}  =\\
     \mylim{y}{y \to \infty}  =\\
     \mylim{k}{k \to -\infty}  =
   \end{array} 
\]
\end{document}

Addendum to address the OP's follow-up question: If the objective is to make LaTeX ignore -- for the purpose of horizontal alignment, that is -- whatever may be in the subscript below "lim", while still centering that material below "lim", you could make use of the comment provided by @daleif and employ the \smashoperator macro of the mathtools package:

\smashoperator{\lim_{x\to-2}} f(x)

If you have a lot of these expressions and wish to economize on typing (and reduce the number of typos...), you could define a shortcut macro, e.g.,

\newcommand\nlim[1]{\smashoperator{\lim_{#1}}}

and then type \nlim{x\to-2} f(x). Note that if the material in the subscript is sufficiently wide, it will "protrude" into the space to the left and to right of "lim". I think two-sided protrusion is what you're after. However, if you want the subscript material to protrude only on the left but not on the right, use the option [l], i.e., write

\smashoperator[l]{\lim{k\to-\infty}} k

enter image description here

\documentclass[12pt]{article}
\usepackage{mathtools} % for \smashoperator macro
\newcommand\nlim[1]{\smashoperator{\lim_{#1}}}
\begin{document}
\[ \begin{array}{|@{}l}
     \nlim{x \to -2} x =\\
     \nlim{x \to -1} x =\\
     \nlim{x \to 0} x =\\
     \nlim{x \to 1} x =\\
     \nlim{x \to 2} x =\\
     \nlim{y \to \infty} y =\\
     \nlim{k \to -\infty} k =
   \end{array} 
\]
\end{document}

A comment on the aesthetics produced by \mylim and \nlim: If you're going to make the effort to align various rows on the string "lim", you shouldn't risk marring the overall look by letting lim's subscript material protrude to the left of the string. In my opinion, then, you should go with \mylim rather than with \nlim to achieve your alignment objective.