# How to make an equation more compact?

I have an equation that wastes a lot of space around the union symbol:

\documentclass{article}

\usepackage[cmex10]{amsmath}
\usepackage{amssymb}

\begin{document}
$$RA_U \left ( new , ref \right ) = \bigcup_{ \left\{ i \text{ such that } f_i \left( ref \right) < f_i \left( new \right) \right\} } \left\{ X \in \mathbb{R}^M ; x_i \in \left [ f_i \left( ref \right) ; f_i \left( new \right) \right ] \right\}$$
\end{document}


This is especially dreadful, since I am using IEEEtran.cls, which has two columns.

How can I compress the equation around the union symbol?

-
Don't use the cmex10 option for amsmath; it's just for compatibility with very old TeX distributions. – egreg Nov 22 '13 at 16:50
I can't see the meaning of this formula. Is $X=(x_1,x_2,...x_m)$? If so, you are quantifying over $i$ twice, once in the \bigcup and again in the set to its right. This is a mathematical error. – Dan Nov 23 '13 at 3:49
I second Dan's comment. Ignoring that, it usually is sufficiently clear to simply have f_i(ref) < f_i(old) below the \bigcup since i is the only free variable. – Caramdir Nov 23 '13 at 17:18
Gnnnn ... must .... not .... give .... stupid ... answer ... to ... title ...... gaaahdamnIcantresist: algebra! – Christian Nov 26 '13 at 20:46

You can use \mathclap from mathtools package:

\documentclass{article}

\usepackage[cmex10]{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}

\begin{document}
$$RA_U ( \mathit{new}, \mathit{ref} ) = \bigcup_{\mathclap{ \left\{ i \text{ such that } f_i (\mathit{ref}) < f_i ( \mathit{new} ) \right\} }} \left\{ X \in \mathbb{R}^M ; x_i \in [ f_i ( \mathit{ref} ) ; f_i ( \mathit{new} ) ] \right\}$$
\end{document}


Output:

-
Better than mine, but I think that a qquad space on either side of the \bigcup will make it look much better (or pushing the subscript a bit down vertically with some \strut). – Rmano Nov 22 '13 at 16:47
@Rmano This is left to the OP's taste. – karlkoeller Nov 22 '13 at 16:50
Hmmm, something bad will happen if one put two \bigcup_{\mathclap{\text{longgggg}}}s together. Having no idea about this further more question, I got a ':(' from myself... – Ch'en Meng Nov 22 '13 at 17:00
@Ch'enMeng, you can either let TeX arrange your equations, or take matters in your own hands. If you don't want to mash two subscripts together, just don't do it. – alexis Nov 22 '13 at 21:05

I recommend you do the following:

• Get rid of all \left and \right directives since they (a) insert undesirable horizontal whitespace and (b) don't actually do anything useful in the present context.

• Use \substack (provided by the amsmath package) to break the line below \bigcup into two parts.

• Use \textup (or \textnormal) instead of the default math italics in the definitions of the variable names "ref" and "new".

• Use \mathclap (provided by the mathtools package) to suppress whitespace to the left and right of \bigcup. (This step is also featured in @karlkoeller's answer.)

\documentclass{article}
\usepackage{mathtools,amssymb}
\newcommand\vnew{\textup{new}}
\newcommand\vref{\textup{ref}}
\begin{document}
Before:
$$RA_U \left ( new , ref \right ) = \bigcup_{ \left\{ i \text{ such that } f_i \left( ref \right) < f_i \left( new \right) \right\} } \left\{ X \in \mathbb{R}^M ; x_i \in \left [ f_i \left( ref \right) ; f_i \left( new \right) \right ] \right\}$$

After:
$$RA_U (\vnew,\vref) = \bigcup_{ \mathclap{ \substack{i\text{ such that}\\f_i(\vref) < f_i(\vnew)}} } \, \bigl\{ X\in\mathbb{R}^M ; x_i \in [ f_i(\vref) ; f_i(\vnew) ] \bigr\}$$
\end{document}

-
Wow! Thank you! This is so beautiful. – Martin Drozdik Nov 22 '13 at 16:48
I would leave some space around \bigcup. Other than that, this looks very good to me :) – yo' Nov 22 '13 at 17:00
@tohecz - Thanks! I did insert \, (thinspace) to the right of \bigcup ... :-) Since space is at a premium, I chose not to insert any more space. – Mico Nov 22 '13 at 17:03

This is not new with respect to other answers, but I'd like to introduce a couple of tricks:

\documentclass{article}

\usepackage{amsmath,mathtools}
\usepackage{amssymb}

\newcommand{\V}[1]{\mathrm{#1}} % or \mathit
\newcommand{\numberset}[1]{\mathbb{#1}}
\newcommand{\R}{\numberset{R}}

\begin{document}
This is the original equation
$$RA_{U}(\V{new},\V{ref}) = \bigcup_{ \quad \mathclap{\substack{ \text{i such that}\\[\jot] f_i(\V{ref}) < f_i(\V{new}) }} \quad } \{ X \in \R^{M} : x_i \in [f_i(\V{ref}); f_i(\V{new})] \}$$

\renewcommand{\V}[1]{\mathit{#1}}
\renewcommand{\numberset}[1]{\mathsf{#1}}

Just to see the effect of changing just a couple of commands
$$RA_{U}(\V{new},\V{ref}) = \bigcup_{ \quad \mathclap{\substack{ \text{i such that}\\[\jot] f_i(\V{ref}) < f_i(\V{new}) }} \quad } \{ X \in \R^{M} : x_i \in [f_i(\V{ref}); f_i(\V{new})] \}$$
\end{document}


The main trick is the macro \V for typesetting multiletter variables; then also \numberset is defined, which is used indirectly for defining \R (and other number sets). I show how, just changing those definitions, one can change the output.

For the wide subscript I use \substack in a \mathclap, but adding some space around it in order that the union symbol is not adjacent to its surroundings.

Note the \jot used for giving some room between the two lines in the subscript. Also \text{$i$ such that} is handier to type than i\text{ such that}, because spaces are ‘natural’.

-
The \V macro is really nifty! – Mico Nov 22 '13 at 17:18
What is your view on the relative advantages of using \textup vs. \mathrm for typesetting variable names (assuming, of course, that an upright font shape is to be used)? In my experience, \textup yields slightly more tightly spaced letters, which may (or may not...) be desirable. – Mico Nov 22 '13 at 22:02
@Mico The difference is that one is typeset as normal text, the other in math, which has different rules for kerning. For variable names probably \mathrm (just like operator names); for words in subscript probably text; example: $F_{\textup{eff}}$. Maybe \textnormal is even better. – egreg Nov 22 '13 at 22:26

Firstly don;t use \left...\right all over the place, it is not a good idea.

Why not just write \{ i \mid f_i ( ref ) < f_i ( new ) \} ( it looks better to add space around the |)

-
What is objectionable about using \left...\right? – Olivier Bégassat Nov 22 '13 at 16:29
@Olivier I am also trying to find out. This seems to be a good resource tex.stackexchange.com/questions/12773/or-left-parentheses – Martin Drozdik Nov 22 '13 at 16:31
Hmmm, bypassing the problem rather than sloving it... – Ch'en Meng Nov 22 '13 at 16:33
@OlivierBégassat - Since space is at a premium in the present equation, all instructions that needlessly insert whitespace should be avoided, right? – Mico Nov 22 '13 at 16:47
Use \left...\right when appropriate. Trying to auto scale all over the places makes the code much harder to read. There is no reason to use scaling in say \left( new \right) as the fenced material is not tall. Instead it just clutters the code. – daleif Nov 22 '13 at 17:01

I would write the index to the joint in two lines as

You can obtain this through

\documentclass{article}

\usepackage[cmex10]{amsmath}
\usepackage{amssymb}

\begin{document}
$$RA_U \left ( new , ref \right ) = \mkern-36mu \bigcup_{ i, \atop f_i \left( ref \right) < f_i \left( new \right) } \mkern-36mu \left\{ X \in \mathbb{R}^M ; x_i \in \left [ f_i \left( ref \right) ; f_i \left( new \right) \right ] \right\}$$
\end{document}


Note that I addtionally customized the kerning by hand. You can use the mathtools package as well (see @Micos answers for example).

## Edit

According to @egregs comment I'd like to present a variety using the \substack command provided by amsmath that yelds better results regarding the size of the index:

$$RA_U \left ( new , ref \right ) = \mkern-40mu \bigcup_{ \substack{ i, \\ f_i \left( ref \right) < f_i \left( new \right) } } \mkern-40mu \left\{ X \in \mathbb{R}^M ; x_i \in \left [ f_i \left( ref \right) ; f_i \left( new \right) \right ] \right\}$$

-
Thank you! This looks even better – Martin Drozdik Nov 22 '13 at 16:49
amsmath has \substack which is better than \atop. – egreg Nov 22 '13 at 16:49

It is visual formatting, so it's better avoided if you can, but you can do:

$$RA_U \left ( new , ref \right ) = \qquad\bigcup_{\mathstrut\makebox[0pt][c]{ \left\{ i \text{ such that } f_i \left( ref \right) < f_i \left( new \right) \right\} } } \qquad \left\{ X \in \mathbb{R}^M ; x_i \in \left [ f_i \left( ref \right) ; f_i \left( new \right) \right ] \right\}$$


To obtain

-