29

I am quite new to TeX. I want that each line in the following equation be centered, but I cannot find how to do it.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{split}
a & = \frac{M_{20}}{M_{00}} - x^{2}_{c}, \;\;\;
b = 2(\frac{M_{11}}{M_{00}} - x_{c}y_{c}), \;\;\;
c = \frac{M_{02}}{M_{00}} - y^{2}_{c}, \\
&\quad x_{c} = \frac{M_{10}}{M_{00}}, \;\;\;
y_{c} = \frac{M_{01}}{M_{00}}, \\
&\quad M_{ij} = \displaystyle\sum\limits_{x} \displaystyle\sum\limits_{y} x^i y^j I(x,y)
\end{split}
\end{equation}
\end{document}

Also, it would be awesome if I could write "and" after the first line ;)

Thanks in advance

2
  • It's always best to have compilable code. Jan 19, 2011 at 10:39
  • Check out Philipp's answer. Embedding of gathered in equation puts one centered equation number nexts to centered equations. The accepted answer forces the equation number onto the last line and a large number of \notag commands.
    – Argyll
    May 2, 2014 at 11:51

4 Answers 4

16
\documentclass{minimal}
\usepackage{amsmath}

\begin{document}

\begin{gather}
a  = \frac{M_{20}}{M_{00}} - x^{2}_{c},\quad
b = 2(\frac{M_{11}}{M_{00}} - x_{c}y_{c}),\quad
c = \frac{M_{02}}{M_{00}} - y^{2}_{c},\nonumber\\[1ex]
\text{and}\nonumber\\[1ex]
x_{c} = \frac{M_{10}}{M_{00}},\quad
y_{c} = \frac{M_{01}}{M_{00}}, \nonumber\\
M_{ij} = \displaystyle\sum\limits_{x} \displaystyle\sum\limits_{y} x^i y^j I(x,y)
\end{gather}

\end{document}

alt text

4
  • Instead of \displaystyle\sum\limits_{x} you can write \sum_{x} Jan 19, 2011 at 11:07
  • 1
    or \sum_x... :-)
    – user2478
    Jan 19, 2011 at 11:17
  • I used '\displaystyle\sum\limits_{x}' since the position of limit is a little bit different from '\sum_{x}'. With '\displaystyle\sum\limits_{x}' it actually goes below '\sum'.
    – nacho4d
    Jan 19, 2011 at 12:11
  • Inside an equation environment it is already at displaystyle, and the subscript will be placed below. amsmath also defined the \intertext{} command which is made for exactly for inserting a short text between equations like this. Jan 19, 2011 at 12:41
31

Just replace the split environment by gathered, then you don't have to suppress spurious equation numbers:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{gathered}
a = \frac{M_{20}}{M_{00}} - x^{2}_{c}, \;\;\;
b = 2(\frac{M_{11}}{M_{00}} - x_{c}y_{c}), \;\;\;
c = \frac{M_{02}}{M_{00}} - y^{2}_{c}, \\
\quad x_{c} = \frac{M_{10}}{M_{00}}, \;\;\;
y_{c} = \frac{M_{01}}{M_{00}}, \\
\quad M_{ij} = \displaystyle\sum\limits_{x} \displaystyle\sum\limits_{y} x^i y^j I(x,y)
\end{gathered}
\end{equation}
\end{document}
4
  • 3
    This should be definitely the right answer...
    – GiuTeX
    Aug 5, 2017 at 10:17
  • 1
    @GiuTeX why? Is it significantly different from the accepted answer?
    – Nathan
    Dec 5, 2021 at 22:34
  • 1
    @Nathan gotta be honest with you I don't remember at all why I wrote that. Looking now at the accepted answer I can't say there are substantial differences...
    – GiuTeX
    Dec 7, 2021 at 10:53
  • 1
    @GiuTeX other voters seem to agree with you, though. I suppose the abstracting-away of other subtleties and just leaving the votes to speak probably mean you're right
    – Nathan
    Dec 7, 2021 at 21:52
4

The code below is not exactly what you asked for, but it has some alternatives that you might want consider.

  • Use \left and \right to fix the size of the parenthesis
  • Use \intertext to put words between equations
  • Use & to get better control of alignment

You mentioned you are new. You might want to read the mathtools document.


\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a &= \frac {M_{20} } {M_{00} } - x^{2}_{c} , &
b &= 2 \left (  \frac {M_{11} } {M_{00} } - x_{c} y_{c}  \right )  , & %NOTE THE \LEFT AND \RIGHT
c &= \frac {M_{02} } {M_{00} } - y^{2}_{c} , \\
\intertext {and} % NOTE THE 'CORRECT' USAGE OF INTERTEXT TO WRITE IN BETWEEN EQUATIONS
&& \quad x_{c} &= \frac {M_{10} } {M_{00} } , & % NOTE THE DOUBLE && TO ALIGN TO THE SECOND COLUMN
y_{c} &= \frac {M_{01} } {M_{00} } , \\
\intertext {Some text}
&& \quad M_{ij} &= \sum \limits_{x} \sum \limits_{y} x^i y^j I( x, y )
\end{align}
\end{document}
3
\documentclass{article}   
\usepackage{amsmath}   
\begin{document}

\begin{gather}
a = \frac{M_{20}}{M_{00}} - x^{2}_{c}, \;\;\; 
    b = 2\left(\frac{M_{11}}{M_{00}} - x_{c}y_{c}\right), \;\;\;
    c = \frac{M_{02}}{M_{00}} - y^{2}_{c}, \nonumber\\
x_{c} = \frac{M_{10}}{M_{00}}, \;\;\; y_{c} = \frac{M_{01}}{M_{00}}, \\
M_{ij} = \sum_x\sum_y x^i y^j I(x,y)\nonumber
\end{gather}

\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.