# How can I make LaTeX ignore height of underbrace?

I have created this matrix:

With this LaTeX-Code:

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage{amsmath,array}
\renewcommand\arraycolsep{4pt} % default value: 6pt

\begin{document}
\begin{preview}
\begin{equation*}
\left( \,
\begin{array}{r@{}r@{}r r r}  % @{} is used twice to suppress intercolumn whitespace
\overbrace{
\boxed{
\begin{array}{rrr}    % First block (1)
1 &        &   \\
& \ddots &   \\
&        & 1 \\
\end{array}
}
}^{r_+(s)-mal} \\
&
\underbrace{
\boxed{
\begin{array}{rrr}    % Second block (-1)
-1 &        &   \\
& \ddots &   \\
&        & -1\\
\end{array}
}
}_{r_{-}(s)-mal} \\
& &
\underbrace{
\boxed{
\begin{array}{rrr}    % Third block
0  &        &  \\
& \ddots &  \\
&        & 0\\
\end{array}
}
}_{r_0(s)-mal} \\
\end{array}\,\right)
\end{equation*}
\end{preview}
\end{document}


You can see that the underbrace causes the third block to appear a little lower than it would without the underbrace of the second block. But I don't want the third block to appear lower.

How can I make LaTeX ignore the height of the second underbrace?

It would be even better, if I could make diagonal braces and remove the blocks. But I guess thats complicated.

-

A solution using TikZ for diagonal braces:

\documentclass{article}
\usepackage{amsmath,array}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\setlength\arraycolsep{4pt} % default value: 6pt

\newcommand\tikzmark[1]{%
\tikz[overlay,remember picture,baseline] \coordinate [anchor=base] (#1);}

\newcommand\DrawBrace[3]{%
\draw [decorate,decoration={brace,amplitude=2pt,mirror,raise=2pt}]
(#1) -- (#2) node [black,midway,sloped,yshift=-10pt] {\footnotesize$#3$};
}

\begin{document}

\begin{equation*}
\left(
\begin{array}{*{9}{c}}
\tikzmark{a}\phantom{-}1 \\
& \ddots & \\
& & \tikzmark{b}\phantom{-}1 \\
& & & \tikzmark{c}-1 \\
& & & & \ddots & \\
& & & & & \tikzmark{d}-1\\
& & & & & & \tikzmark{e}\phantom{-}0 \\
& & & & & & & \ddots & \\
& & & & & & & & \tikzmark{f}\phantom{-}0 \\
\end{array}
\right)
\end{equation*}

\begin{tikzpicture}[remember picture,overlay]
\DrawBrace{a}{b}{r_{+}(s)-mal}
\DrawBrace{c}{d}{r_{-}(s)-mal}
\DrawBrace{e}{f}{r_{0}(s)-mal}
\end{tikzpicture}
\end{document}


-
Thanks for your solution. Why do you make a % at the end of your \newcommand-lines? – Martin Thoma Sep 2 '12 at 18:19
@moose in this particular case, the % characters are not necessary, but in certain circumstances they help to prevent spurious blank spaces which might produce undesired results. – Gonzalo Medina Sep 2 '12 at 21:49

Not really an elegant solution. Basically, all that is needed is to set the additional vertical space produced by the \underbrace to zero. One easy tool for this is \raisebox which in its first and second optional argument allows to give an explicit height and depth for the resulting box.

Two complications:

1. The inner array comes out vertically centered, so the height and depth of the \underbrace construct are murky.
2. Some additional vertical space is inserted in the outer array if one of the lines has depth zero, so the whole boxed construct must be lowered again.

\begin{equation*}
\left( \,
\begin{array}{r@{}r@{}r r r}  % @{} is used twice to suppress intercolumn whitespace
\overbrace{
\boxed{
\begin{array}{rrr}    % First block (1)
1 &        &   \\
& \ddots &   \\
&        & 1 \\
\end{array}
}
}^{r_+(s)-mal} \\
&
\raisebox{-.5\height}[.5\height][.5\height]
{%
$\underbrace{ \raisebox{\depth} {%$\boxed{
\begin{array}{rrr}    % Second block (-1)
-1 &        &   \\
& \ddots &   \\
&        & -1\\
\end{array}
}$% }% }_{r_{-}(s)-mal}$%
}%
\\
& &
\underbrace{
\boxed{
\begin{array}{rrr}    % Third block
0  &        &  \\
& \ddots &  \\
&        & 0\\
\end{array}
}
}_{r_0(s)-mal} \\
\end{array}\,\right)
\end{equation*}


-

There must be a tikzmark way. But I don't have time now. Meanwhile, an ugly hack will be to manually shrink the space using \\[length] as in

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage{amsmath,array}
\renewcommand\arraycolsep{4pt} % default value: 6pt

\begin{document}
\begin{preview}
\begin{equation*}
\left( \,
\begin{array}{r@{}r@{}r r r}  % @{} is used twice to suppress intercolumn whitespace
\overbrace{
\boxed{
\begin{array}{rrr}    % First block (1)
1 &        &   \\
& \ddots &   \\
&        & 1 \\
\end{array}
}
}^{r_+(s)-mal} \\
&
\underbrace{
\boxed{
\begin{array}{rrr}    % Second block (-1)
-1 &        &   \\
& \ddots &   \\
&        & -1\\
\end{array}
}
}_{r_{-}(s)-mal} \\[-17pt]         %%% <--Here
& &
\underbrace{
\boxed{
\begin{array}{rrr}    % Third block
0  &        &  \\
& \ddots &  \\
&        & 0\\
\end{array}
}
}_{r_0(s)-mal} \\
\end{array}\,\right)
\end{equation*}
\end{preview}
\end{document}


Little eye-balling would be needed to estimate the appropriate value for \\[-17pt], though.

-