3

I am trying to align the symbol plus with \shortintertext I tried

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align*}
\shortintertext{We have}
   1 + 2 + 3 + \cdots + n &= \dfrac{n(n+1)}{2} \\
\shortintertext{and}
   1^2 + 2^2 + 3^2 + \cdots + n^2 &= \dfrac{n (n+1) (2 n+1)}{6} 
\end{align*}
\end{document} 

enter image description here

How can I got the result like this picture (still contain "we have", "and")
enter image description here

5

You have to insert multiple alignment points. You can do it with alignat:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{alignat*}{5}
\shortintertext{We have}
   &1   && + 2   &&+ 3   &&+ \cdots + n   &&= \dfrac{n(n+1)}{2} \\
\shortintertext{and}
   &1^2 && + 2^2 &&+ 3^2 &&+ \cdots + n^2 &&= \dfrac{n (n+1) (2 n+1)}{6} 
\end{alignat*}
\end{document}

enter image description here


Another approach, with a little extra work maybe, would be to add ^\phantom{2} in the first equations wherever there is a ^2 in the second equation. To make things easier I defined a macro \ph to do this:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\def\ph{^{\phantom{2}}}%
\begin{align*}
\shortintertext{We have}
   1\ph + 2\ph + 3\ph + \cdots + n\ph &= \dfrac{n(n+1)}{2} \\
\shortintertext{and}
   1^2  + 2^2  + 3^2  + \cdots + n^2  &= \dfrac{n (n+1) (2 n+1)}{6} 
\end{align*}
\end{document}

The result is the same. Note that we need an extra pair of braces around the \phantom.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.