29

I want to get the following:

What I want to have

I tried the following

\[
   a(i,k) \leftarrow 
   \min\Big\{0, r(k,k) + \sum_{i^{'} | i^{'}\notin \{i,k\}}\max\{0, r(i{'},k)\}\Big\}
\]

and got

What I got

How can I make the part under the summation extend to left and right without making a space between plus and max as in the first figure?

yo'
  • 51,322
petrichor
  • 1,869
  • 2
    Such a formula should be between \[ and \], rather than $\displaystyle and $: if set inline it will spoil the appearance of the page. – egreg Jan 12 '13 at 22:29
  • Thanks. But even within the brackets (no inline), I can't remove the extra spaces. – petrichor Jan 12 '13 at 22:35
  • By the way, I noticed that I forgot the extra bracket at the end, I will correct it. – petrichor Jan 12 '13 at 22:36
  • For any future visitors that want to do this in a LaTeX-like environment that doesn't support mathtools, you can use a few dozen \! negative spacers in a pinch. – Brian61354270 Sep 22 '23 at 00:52

3 Answers3

26

Apart from \mathclap{…}, mathtools provides a command specifically set for these situations: \smashoperator{…}. Which is, more or less, like putting \mathclap{…} in both (sub and super scripts). Taking @tohecz advice about a'|a', your code will be like

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\[
   a(i,k) \gets \min\Bigl\{ 0, r(k,k) + \smashoperator{\sum_{i'\notin\{i,k\}}} \max\{0, r(i',k)\} \Bigr\}
\]
\end{document}

Which will be like all the other answers. Moreover, that command has an optional argument: lr, default one, will smash both sides; r only smash the right; and l will smash the left. In the examples I will add some text over the operator so you can see how it works (it smashes both).

enter image description here

Manuel
  • 27,118
14

You can load the package mathtools and write:

\[
   a(i,k) \leftarrow 
   \min\Big\{0, r(k,k) + \sum_{\mathclap{i'\mid i'\notin \{i,k\}}}
   \max\{0, r(i',k)\}\Big\}
\]

However, I always prefer some space left around such sum:

enter image description here

\[
   a(i,k) \leftarrow 
   \min\Big\{0, r(k,k) + \;\sum_{\mathclap{i'\mid i'\notin \{i,k\}}}\;
   \max\{0, r(i',k)\}\Big\}
\]

As well:

  • Notice that the syntax for the prime is neither i^{'} nor i{'}. It is i'.

  • It might be better to use \mid instead of |. Here, the result is the same, but the symbol | has four different meanings (relation, operator, open delim, close delim), and it is a good practice to always use one of \mid, \vert, \lvert, \rvert.

  • In my opinion, \sum_{i|i\notin X} is redundant, you can write just \sum_{i\notin X}. It is a common practice that summation is over the very first variable in the sum's index.

  • Typing \Bigl\{ ... \Bigr\} instead of \Big\{...\Big\} costs two keystrokes more, and you keep the sematics correctly, as well in some cases it is necessary (absolute value |.|, reverse-bracket open intervals ].[ etc.)

  • You can make the braces after \max bigger, it doesn't cost any space and it increases readibility and visual appearance.

enter image description here

\[
   a(i,k) \leftarrow 
   \min\Bigl\{0, r(k,k) + \;\sum_{\mathclap{i'\notin \{i,k\}}}\;
   \max\bigl\{0, r(i{'},k)\bigr\}\Bigr\}
\]
yo'
  • 51,322
  • I'd prefer \mid instead of |; the result here is the same, but it reminds to use it also in text or display style. – egreg Jan 12 '13 at 22:43
  • I think you should talk about \smashoperator{…} which was designed for this (i.e., it helps if you have to smash the subscript and the superscript). – Manuel Jan 12 '13 at 23:01
  • @Manuel You can post it as a seperate answer I think. I haven't known it even exists so I'll be glad to see an example of its usage. – yo' Jan 12 '13 at 23:03
8

You can use \mathclap{....} from mathtools:

\documentclass{article}
\usepackage{mathtools}
%
\begin{document}
 \[
   a(i,k) \leftarrow 
   \min\Big\{0, r(k,k) + \sum_{\mathclap{i^{'} | i^{'}\notin \{i,k\}}}\max\{0, r(i{'},k)\}\Big\}
\]
\end{document}

enter image description here