5
  \begin{equation}
    S=\sum\limits_{i=1}^{8}A_i
    S=\sum\limits_{i=1}^{8}B_i
    S=\sum\limits_{i=1}^{8}C_i
    S=\sum\limits_{i=1}^{8}D_i
  \end{equation}

Considering the above code, I am so interested to know that how it is possible to print these 4 equations, one per line, instead of all followed in one single line.

lonesome
  • 565

3 Answers3

11

Package amsmath provides many environments for equations, e.g.:

  • gather for centering equations by default
  • align, which allows vertical alignments

Example:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
  \begin{gather}
    S=\sum_{i=1}^{8}A_i\\
    S=\sum_{i=1}^{8}B_i\\
    S=\sum_{i=1}^{8}C_i\\
    S=\sum_{i=1}^{8}D_i
  \end{gather}
  \begin{align}
    S &= \sum_{i=1}^{8}A_i\\
    S &= \sum_{i=1}^{8}B_i\\
    S &= \sum_{i=1}^{8}C_i\\
    S &= \sum_{i=1}^{8}D_i
  \end{align}
\end{document}

Result

Equation number in last line

\documentclass{article}
\usepackage{amsmath}

\begin{document}
  \begin{gather}
    \nonumber S=\sum_{i=1}^{8}A_i\\
    \nonumber S=\sum_{i=1}^{8}B_i\\
    \nonumber S=\sum_{i=1}^{8}C_i\\
    S=\sum_{i=1}^{8}D_i
  \end{gather}
  \begin{align}
    \nonumber S &= \sum_{i=1}^{8}A_i\\
    \nonumber S &= \sum_{i=1}^{8}B_i\\
    \nonumber S &= \sum_{i=1}^{8}C_i\\
    S &= \sum_{i=1}^{8}D_i
  \end{align}
\end{document}

Result equation number in last line

Equation number in the middle

\documentclass{article}
\usepackage{amsmath}

\begin{document}
  \begin{equation}
  \begin{gathered}
    S=\sum_{i=1}^{8}A_i\\
    S=\sum_{i=1}^{8}B_i\\
    S=\sum_{i=1}^{8}C_i\\
    S=\sum_{i=1}^{8}D_i
  \end{gathered}
\end{equation}
\begin{equation}
  \begin{aligned}
    S &= \sum_{i=1}^{8}A_i\\
    S &= \sum_{i=1}^{8}B_i\\
    S &= \sum_{i=1}^{8}C_i\\
    S &= \sum_{i=1}^{8}D_i
  \end{aligned}
\end{equation}
\end{document}

Result equation number in the middle

Addendum: sign function definition with cases

\documentclass{article}
\usepackage{amsmath}
\usepackage{colonequals}

\DeclareMathOperator{\sgn}{sgn}

\begin{document}
  \begin{equation}
    \sgn(x) \colonequals
    \begin{cases}
      -1 & \text{if } x < 0 \\
      0  & \text{if } x = 0 \\
      1  & \text{if } x > 0
    \end{cases}
  \end{equation}
\end{document}

Result sgn function

Heiko Oberdiek
  • 271,626
4

You also can have several alignment points per line. For one number for each group, use the nested environments: gathered, aligned, multlined (the latter if you load mathtools instead of amsmath). You also can have subnumbering (1a, 1b, &c.) with the subequations environment:

\documentclass{article}
\usepackage{mathtools}
\usepackage{showframe}

\begin{document}
  \begin{align}
    S &= \sum_{i=1}^{8}A_i &S &= \sum_{i=1}^{8}B_i\\
    S &= \sum_{i=1}^{8}C_i & S &= \sum_{i=1}^{8}D_i
  \end{align}

  \begin{flalign}
    S &= \sum_{i=1}^{8}A_i &S &= \sum_{i=1}^{8}B_i & S &= \sum_{i=1}^{8}C_i \\
    S &= \sum_{i=1}^{8}D_i & S &= \sum_{i=1}^{8}D_i & S &= \sum_{i=1}^{8}F_i
  \end{flalign}

  \begin{align*}
    S &= \sum_{i=1}^{8}A_i &S &= \sum_{i=1}^{8}B_i & S &= \sum_{i=1}^{8}C_i \\
    S &= \sum_{i=1}^{8}D_i & S &= \sum_{i=1}^{8}D_i & S &= \sum_{i=1}^{8}F_i
  \end{align*}

\begin{equation}\label{myeq}
      \begin{aligned}
        S &= \sum_{i=1}^{8}A_i &S &= \sum_{i=1}^{8}B_i\\
        S &= \sum_{i=1}^{8}C_i & S &= \sum_{i=1}^{8}D_i
      \end{aligned}
\end{equation}
\end{document}

enter image description here

Bernard
  • 271,350
  • Can we center aligned equations? – alper Jan 22 '22 at 11:05
  • If you have one equation per row, they're all aligned. In the last possibility I propose (two equations per row), it is each group oftwo equations which is centred – Bernard Jan 22 '22 at 14:02
2

Or

\documentclass{amsart}

\begin{document}


\begin{gather}
\left\{
\begin{aligned}
    S &=\sum\limits_{i=1}^{8}A_i,\\
    S&=\sum\limits_{i=1}^{8}B_i,\\
    S&=\sum\limits_{i=1}^{8}C_i,\\
    S&=\sum\limits_{i=1}^{8}D_i.
  \end{aligned}
  \right.
  \end{gather}

  \end{document}

enter image description here

JPi
  • 13,595
  • 1
    lovely, where is the placement for label? – lonesome Aug 21 '15 at 16:59
  • if you want the equation numbers on the right then you can just write \documentclass[reqno]{amsart} instead. If you want an equation number for each line then search this forum for numcases. – JPi Aug 21 '15 at 17:04
  • no no, you mistook me. What I meant is where to place a caption/label so I can reference it within my article, using \ref{}. – lonesome Aug 21 '15 at 17:07
  • I disagree. If it was possible to put it anywhere, I wouldn't ask it. – lonesome Aug 21 '15 at 17:17
  • As an extension to this question, how is it possible to print equation with curly brackets, but for one single function? This is very common in Math to face functions which returns a set of constants regarding to a particular range of inputs. To illustrate these type of functions, there are curly brackets which illustrating them. I hope you do understand me. something like Sing function – lonesome Aug 21 '15 at 17:23
  • 1
    You can write \label{myeq} anywhere between \begin{gather} and \end{gather} and use \ref{myeq} elsewhere in your document. – JPi Aug 21 '15 at 17:30
  • right. I had a spelling error so that is why did not work in the first place. :) – lonesome Aug 21 '15 at 17:32