# \left[ and \right] resizing differently for very similar formulae. Don't know how to fix it.

I have a \newcommand which inserts left and right square brackets around whatever you pass it.

\documentclass{minimal}
\newcommand{\foo}[1]{\left[#1\right]}
\begin{document}
Since $\foo{B} = \foo{\sum_j b_jB_j}$ and $\foo{C} = \foo{\sum_i c_i C_i}$ by definition.
\end{document}

This outputs:

Notice that the square brackets around the sum in the C equation are much smaller than those in the B equation. Why is this happening and can I avoid having to manually change the size each time? I am using these square brackets a lot throughout a large document and would really like to avoid it.

-
I would say, this is the cause of the descender of the letter j -- contrary to i which doesn't have this descender. – Christian Hupfer Feb 1 at 11:42
Hmmm.. You are correct that it does seem that changing j to i makes the B brackets small as well. That is a shame as I think the second equation looks ugly with the sigma going outside of the square brackets. – ChrisCampbell19 Feb 1 at 11:44

The different height of the brackets is caused by the descender of the letter j compared to i.

One way: Use k instead of j (or any other letter without descender)

Or perhaps using \bigl[ and \bigr] is an option (or if scaling isn't an issue \big[ and \big]?)

\documentclass{article}
\usepackage{amsmath}
\newcommand{\foo}[1]{\bigl[#1\bigr]}
\begin{document}
Since $\foo{B} = \foo{\sum_j b_jB_j}$ and $\foo{C} = \foo{\sum_i c_i C_i}$ by definition.
\hrule
\end{document}

The \hrule is just for comparison only. Certainly, there are other ways to achieve this.

Note: \big[ etc. works too, but the scaling is different. It's a matter of taste rather then a law.

-
I am going to use \big for now as this at least makes the sizing consistent. I think I will define a different function \bar for with \biggr brackets for expressions with sum in. Thanks for the help! – ChrisCampbell19 Feb 1 at 11:55
Another way: you could \smash the js. – wchargin Feb 1 at 20:59
One could also take the biggest formula and add it as a \vphantom, thus eliminating the need to try out the sizes of different brackets – Turion Feb 1 at 21:40
@Turion: I hadn't seen your comment, I think as you that \vphantom is what is natural to use in such a case, I made it an answer. – Joce Feb 3 at 8:13
@Joce, that's perfectly fine :) I was just too lazy to write a whole answer. – Turion Feb 3 at 8:53

A simple fix for these annoying little size mismatchs in otherwise similar formulas is to use \vphantom :

Since $\foo{B} = \foo{\sum_j b_jB_j}$ and $\foo{C} = \foo{\sum_{i\vphantom{j}} c_{i\vphantom{j}} C_{i\vphantom{j}}}$ by definition.

One \vphantom should be sufficient of course, in the present case, the one of the \sum operator as its subscript is typeset lower than others.

Alternatively, if you'd rather have all of the same height, you can use \smash on the j subscripts, as suggested by WChargin in a comment. This is useful if the formula is in a multiline paragraph and you want to reduce the extra line spacing.

\documentclass{minimal}
\newcommand{\foo}[1]{\left[#1\right]}
\begin{document}
Since $\foo{B} = \foo{\sum_{\smash{j}} b_jB_j}$ and $\foo{C} = \foo{\sum_i c_i C_i}$ by definition.
\medskip

Since $\foo{B} = \foo{\sum_j b_jB_j}$ and $\foo{C} = \foo{\sum_{\vphantom{j}i} c_i C_i}$ by definition.
\end{document}

-
This is just perfect as well. Thanks so much for the help. – ChrisCampbell19 Feb 4 at 9:03
Compared to the accepted solution, it is a technique that doesn't modify the whole of the document's typesetting, which will generally be thought of an advantage for such a cosmetic problem--although you mention that in your case you want the whole document to behave the same. – Joce Feb 4 at 13:32
You can also use \strut which is defined as \vphantom{(}. – Aditya Feb 17 at 22:50

Another possible solution is having a minimum size automatically:

\documentclass{minimal}
\newcommand{\minsize}{\vrule width 0pt height 1.5ex depth 1ex\relax}
\newcommand{\foo}[1]{\left[\minsize #1\right]}
\begin{document}
Since $\foo{B} = \foo{\sum_j b_jB_j}$ and $\foo{C} = \foo{\sum_i c_i C_i}$
by definition.

Now it will scale up --- but not down:  $\foo{B} = \foo{\sum\limits_\frac{j}{j} b_jB_j}$
\end{document}

...but then it will make the smaller ones too big:

You can adjust the minimum size playing with the height and depth parameters of the rule defined in \minsize.

-