[Tex/LaTex] Vertically asymmetric size variation for parentheses

bracketsmath-modevertical alignment

One of the difficulties I have with writing formulas in LaTeX is that the standard sizing tools for the variable-size operators (parentheses, etc.) do not account for "high" symbols and "low" symbols separately. Thus, for instance, if you write something like

\[ \left(
\sum_{\substack{
0\le i\le m \\ 0<j<n}}
P(i,j)
\right) \]

which (using the amsmath package) produces a summation symbol with two lines of subscript, then the tops of the enclosing parentheses extend well above the top of the text:

rendering of the example

Things get vastly worse if you try to enclose a commutative diagram in parentheses.

Is there any way to make the size vary asymmetrically? The parentheses should be able to extend far down without having to extend far up, and vice versa.

Best Answer

There's probably a package to do this ... but in the meantime, here's a way to do it that keeps the baseline correct. It lowers the line by a specified amount just before the opening parenthesis and then raises it back to where it should be just after. Then it does the same again the other end. One could add additional options to have one command deal with all styles of parenthesis and to deal with inline versus displaystyle (this is for displaystyle) - I'd wait to see if there's a package before tackling that! The drawback of this is that you have to decide what the "drop" should be for yourself. A more sophisticated approach would compute that for you.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\lowerparen}[2]{%
  \raisebox{-#1}{\(\displaystyle\left(\raisebox{#1}{\(\displaystyle #2\)}\right)\)}}

\begin{document}
\[
  Y = \lowerparen{6pt}{\sum_{\substack{0 \le i \le m \\ 0 < j < m}}X}
\]

\end{document}

Here's a slightly fuller solution, based on the above but with a little more flexibility with regard to mathmodes (thanks to this question on mathmodes).

\documentclass{article}

\newlength{\parenheight}
\newlength{\parendepth}
\newlength{\parendrop}

\newcommand{\paren}[4]{%
\settoheight{\parenheight}{\(#4 #2\)}%
\settodepth{\parendepth}{\(#4 #2\)}
\addtolength{\parendepth}{.5ex}
\addtolength{\parenheight}{-.5ex}
\addtolength{\parenheight}{\parendepth}
\addtolength{\parendepth}{-.5\parenheight}
\setlength{\parendrop}{-.5\parenheight}
\addtolength{\parendrop}{.5ex}
\raisebox{-\parendepth}{\(#4
\left#1%
\rule[\parendrop]{0pt}{\parenheight}%
\right.\)}
#2
\raisebox{-\parendepth}{\(#4
\left.%
\rule[\parendrop]{0pt}{\parenheight}%
\right#3\)}
}

\def\myleft#1#2\myright#3{%
\mathchoice{%
\paren{#1}{#2}{#3}{\displaystyle}%
}{%
\paren{#1}{#2}{#3}{\textstyle}%
}{%
\paren{#1}{#2}{#3}{\scriptstyle}%
}{%
\paren{#1}{#2}{#3}{\scriptscriptstyle}%
}%
}

\begin{document}


\(
  \myleft(\prod_{{s = 0 \atop s \ne 3}} X_s\myright)^2 \left(A\right) \left(x\right)
\)

\[
  \myleft(\prod_{{s = 0 \atop s \ne 3}} X_s\myright)^2 \left(A\right) \left(x\right)
\]

\end{document}

I haven't tested it very much. I suspect that something will break with the way I've coded the 'left-right' matching. The main point is to get the heights lined up.

(As this answer has been accepted, I don't feel I should simply replace the original answer with this new one but it's only a little development of the original so doesn't really deserve a new answer. So I'm posting it as an addendum.)