[Tex/LaTex] Vertical alignment of arrays in an array

arraysmatricesvertical alignment

I need to write a matrix with decorations, and I decided to use arrays in an array. I seem to be able to "almost" achieve what I wanted, but there is a couple of questions I would like to ask.

Here is an example and code. There are 4 sub-arrays in an array.

enter image description here

Q1 The first two columns and the last two columns are aligned well, but I do not know how to make all of them aligned vertically.

I tried to put overbrace/underbace for the first two, but it did not help.

Q2 Is there a way to make the separator starting/ending from the first row and the last row, not from the starting and ending point of overbrace/underbrace?

I tried to play with Bigl and Bigr, but I did not succeed.

\documentclass{amsart}
\usepackage{amsmath}

\begin{document}

\begin{equation}
\begin{array}{c|c|cc}
\begin{array}{c}
x
\end{array}
&
\overbrace{
\left[ 
\begin{array}{c}
* 
\end{array} \right.
}^{f}
&
\overbrace{
\begin{array}{c|c}
\underbrace{
\begin{array}{c}
* 
\end{array}
}_{xx~terms}
&
\left.
\begin{array}{cccc}
0 
\end{array}
\right]
\end{array}
}^{g}
\end{array}
\end{equation} 
\end{document}

I also tried \def\arraystretch{2}, but it did not help.

Best Answer

Is this what you mean?

enter image description here

You don't need an array. Just one line of math with over- and under-braces.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\[
x|\overbrace{[\;*\;}^f|\overbrace{\underbrace{*}_{xx\text{ terms}}\mid\;0\;]}^g
\]
\end{document}

It now occurs to me that you may want the overbraces to be inside the delimiters. And I think you want the * terms to be potentially bigger (vertically) as in the following:

enter image description here

The code is more complicated, but all the delimiters will adjust in size. I made a macro for the 3x1 matrix called \vertm just to simplify a bit. Then there is a second macro called \vphnm that is just the first matrix enclosed in a \vphantom command. This is necessary to have the delimiters adjust to the matrix and not to the over and under braces.

Note Werner's suggestion to use mathtools and \mathclap.

Here is the code:

\documentclass{article}
\usepackage{mathtools}

\newcommand{\vertm}{\begin{pmatrix}1\\2\\3\end{pmatrix}}
\newcommand{\vphnm}{\vphantom{\vertm}}

\begin{document}
\[
x\left|\vphnm\right[\!\overbrace{\vertm}^f\left|\vphnm\right.%
    \overbrace{\underbrace{\vertm}_{\mathclap{\text{$xx$ terms}}}%
    \left|\vphnm\;0\right.}^g\left.\vphnm\!\right]
\]

\end{document}
Related Question