7

I have a long equation that I need to wrap into multiple lines. I want to know what is the idiomatic way to align the multiple lines. I made two attempts at it and the results do not look good.

Example 1

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
  \frac{100 (100 + 1)}{2}
    & = 1 + 2 + 3 + 4 + 5 \\
    & + 6 + 7 + 8 + 9 + 10 \\
    & \vdots \\
    & + 96 + 97 + 98 + 99 + 100.  
\end{align*}
\end{document}

Here is the output:

enter image description here

Here all the + signs are aligned with = sign and that of course does not look good. In most mathematics books I see that the + sign is aligned with the first expression after the = sign, i.e., 1 in this case. So I made another attempt at it shown in the next example.

Example 2

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
  \frac{100 (100 + 1)}{2}
  = & 1 + 2 + 3 + 4 + 5 \\
    & + 6 + 7 + 8 + 9 + 10 \\
    & \vdots \\
    & + 96 + 97 + 98 + 99 + 100.  
\end{align*}
\end{document}

Here is the output:

enter image description here

This is closer to what I find in mathematics books but this is far from perfect. The = sign is sticking too close to the 1 after it. The \vdots appears misaligned.

I am wondering if there is an idiomatic way to typeset something like this in LaTeX? If yes, I would like to learn about it and use that.

8
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{mathtools}

\begin{document}
\begin{align*}
\frac{100 (100 + 1)}{2} 
    &= \begin{aligned}[t]    
                1 
                &+ 2 + 3 + 4 + 5 \\
                &+ 6 + 7 + 8 + 9 + 10 \\
                &\,\;\vdots \\
                &+ 95 + 96 + 97 + 98 + 99 + 100
        \end{aligned}\\
    &= 5050
\end{align*}
\end{document}

enter image description here

Edit

And don't forget to follow the suggestion of Mico below:

Do consider replacing \,\;\vdots with \shortvdotswithin{+}.

3
  • 2
    Do consider replacing \,\;\vdots with \shortvdotswithin{+}.
    – Mico
    May 2 at 14:56
  • @Mico: Thank you. Doing so will make my answer just another example of plagiarism of the other answers. :-) May 3 at 0:51
  • 1
    Naah, no reason to fear being accused of plagiarism! Just leave a comment that you implemented somebody's suggestion. Honestly, the more examples future readers see of the nifty \shortvdotswithin macro in action, the better. :-)
    – Mico
    May 3 at 1:06
7

The alignment point needn't be at =.

\documentclass{article}
\usepackage{amsmath,mathtools}

\begin{document}

\begin{equation*}
\mathtoolsset{shortvdotsadjustabove=3pt,shortvdotsadjustbelow=-1pt}
\begin{split}
  \frac{100 (100 + 1)}{2} =
    1 &+ 2 + 3 + 4 + 5 \\
      &+ 6 + 7 + 8 + 9 + 10 \\
      & \shortvdotswithin{+}
      &+ 95 + 96 + 97 + 98 + 99 + 100.
\end{split}
\end{equation*}

\end{document}

enter image description here

1
  • Very nice the \mathtoolsset{shortvdotsadjustabove=3pt,shortvdotsadjustbelow=-1pt}. I have seen the documentation and I not known this approach :-).
    – Sebastiano
    May 2 at 11:51
4

One of the following two solutions should be ok. They both use \vdotswithin rather than \vdots, to align the vertical dots on the + symbols. They differ in how the right-hand side of the first row is aligned relative to the right-hand side of the second row.

enter image description here

\documentclass{article}
\usepackage{mathtools} % for \vdotswithin macro
\begin{document}

\begin{align*}
  \frac{100 (100 + 1)}{2}
    & = 1 + 2 + 3 + 4 + 5 \\
    &\quad + 6 + 7 + 8 + 9 + 10 \\
    &\quad \vdotswithin{+} \\
    &\quad + 95 + 96 + 97 + 98 + 99 + 100.  
\end{align*}

\begin{align*}
  \frac{100 (100 + 1)}{2} =
    & \hphantom{{}+{}}1 + 2 + 3 + 4 + 5 \\
    & + 6 + 7 + 8 + 9 + 10 \\
    & \vdotswithin{+} \\
    & + 95 + 96 + 97 + 98 + 99 + 100.  
\end{align*}

\end{document}

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.