I have the following equation, where there is a lot of stuff under the sum symbol:

  \sum_{Z_{xy}\in\vec{Z}_{xy},\forall x\in\vec{x},\forall y\in\vec{y}} 

In the resulting document, I find it kind of hard to read. Is there a way to write the equation to make the result more readable, e.g. putting the stuff under the sum symbol on different lines?

  • Why write under Sum, when mathematical correct is write to right. \begin{equation} d(\vec{x},\vec{y})= \sum_{Z_{xy}\in\vec{Z}_{xy}} f(Z_{xy}),\forall x\in\vec{x},\forall y\in\vec{y} \end{equation}
    – MiMo
    Jun 10, 2012 at 10:34
  • 1
    I agree with you but without the correct spacing, it is as bad as OP's. To be super-picky about it, forall is not the same as over all. With forall the author is relying on the reader's understanding for bad notation.
    – percusse
    Jun 10, 2012 at 13:18
  • 5
    This is mathematically incorrect (if the notation has not introduced formally). But the \forall is definitely misused.
    – egreg
    Jun 10, 2012 at 13:33
  • which font are you using? I love your \sum symbol
    – Peluche
    Dec 4, 2022 at 22:07
  • If you want to write a fraction instead, refer to amsmath - In math mode, how do I make the fraction bar "invisible"? - TeX - LaTeX Stack Exchange.
    – user202729
    Dec 13, 2022 at 6:45

4 Answers 4


You can use the \substack command from the amsmath package, like this:

  d(\vec{x},\vec{y}) =
                  \forall x\in\vec{x}\\
                  \forall y\in\vec{y}}}

However, the result still doesn’t look good, because of the extra spacing around the sum symbol:

Image showing the result of the ‘\substack’ command

To fix this, you can use the \mathclap command from the mathtools package, like this:

 d(\vec{x},\vec{y}) =
                              \forall x\in\vec{x}\\
                               \forall y\in\vec{y}}}}

Image showing the result of the ‘\mathclap’ and ‘\substack’ commands

But perhaps you might be happy using only \mathclap, and not \substack. The result looks good as long as the subscript is not too wide.

  d(\vec{x},\vec{y}) =
          \forall x\in\vec{x},
          \forall y\in\vec{y}}}} f(Z_{xy})

Image showing the result of the ‘\mathclap’ command

The mathtools package also have several other useful commands for typesetting mathematics, including more commands for improving the display of subscripts and superscripts. I very much recommend taking a look at its documentation.

  • 25
    The \forall symbols should be omitted.
    – egreg
    Jun 10, 2012 at 13:34
  • 4
    @egreg: Maybe one should just write three sums in total, the first two over x\in\vec{x} and y\in\vec{y}? Jun 10, 2012 at 13:51
  • 2
    @HendrikVogt I'd use a two line \substack: \sum_{\substack{Z_{xy}\in\vec{Z}_{xy}\\x\in\vec{x},y\in\vec{y}}}
    – egreg
    Jun 10, 2012 at 13:56
  • @KarlOveHufthammer You forgot ` \\ `.
    – Karlo
    Mar 22, 2017 at 14:13
  • Looks good, but seems not to work in rmarkdown's beamer_presentations. Can that be confirmed?
    – jay.sf
    Oct 29, 2017 at 15:26

Try the \substack command from the amsmath package, details of which are found here

  • In case anyone else needs that old link: ctan.org/pkg/amsmath
    – psitae
    Jan 25, 2023 at 20:53
  • 1
    @psitae --- An ftp link! I've been here a long time. I've updated the link in the answer. Jan 27, 2023 at 13:09

[For those who are looking for MathJax way] it can be done without \substack as

\sum_{a=b \\ b=c \\ c=a}

wich results in

enter image description here

  • 3
    doesn't seem to work for me. I am in the 'align' environment.
    – Danyal
    Mar 16, 2021 at 5:22
  • Doesn't work for me, either.
    – relatively
    Jan 20, 2023 at 14:15
  • 3
    This definitely doesn’t work in LaTeX. Unfortunately, it does in MathJax, which is not a reason for advertising it here.
    – egreg
    Jan 22, 2023 at 21:57

Using A \atop B. E.g:

\sum_{{n\in \mathbb{N}}\atop{n= even}}^{100} a_n

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .