1

I have managed to create under braces under my matrix and evened out the spaced using \phantom.

However, there are very large spaces between the columns, the dots, and the brackets. It would be great to make everything more compact horizontally, but I have no idea how to do so.

Could someone help?

\newcommand*{\vertbar}{\rule[-1ex]{0.5pt}{2.5ex}}
\newcommand\undermat[2]{% http://tex.stackexchange.com/a/102468/5764
  \makebox[0pt][l]{$\smash{\underbrace{\phantom{%
    \begin{matrix}#2\end{matrix}}}_{\text{$#1$}}}$}#2}

\begin{align}
    \mathbf{W}_{BA} & 
    \begin{pmatrix}
\vertbar &  & \vertbar & & \vertbar &  & \vertbar  \\
\mathbf{x}^B_1 & \dots & \mathbf{x}^B_1 & \dots & \mathbf{x}^B_p & \dots & \mathbf{x}^B_p  \\
\undermat{k}{\vertbar &  & \phantom{--}\vertbar\phantom{--}} & & \undermat{k}{\vertbar &  & {\phantom{--}\vertbar\phantom{--}}}
\end{pmatrix}
= \notag \\\\
& \begin{pmatrix}
\vertbar &  & \vertbar & & \vertbar &  & \vertbar  \\
\mathcal{N}(\mathbf{x}^B_1)_1 & \dots & \mathcal{N}(\mathbf{x}^B_1)_k & \dots & \mathcal{N}(\mathbf{x}^B_p)_1 & \dots & \mathcal{N}(\mathbf{x}^B_p)_k  \\
\undermat{k}{\vertbar &  & \phantom{---}\vertbar\phantom{---}} & & \undermat{k}{\vertbar &  & {\phantom{---}\vertbar\phantom{---}}}
\end{pmatrix}.
\\
\end{align}

enter image description here

1 Answer 1

1

Below I use some measurements to correctly align the \underbrace width with its contents.

enter image description here

\documentclass{article}

\usepackage{amsmath,xcolor}

\newcommand*{\vertbar}{\rule[-1ex]{0.5pt}{2.5ex}}
\newcommand\undermat[2]{% http://tex.stackexchange.com/a/102468/5764
  \makebox[0pt][l]{$\smash{\underbrace{\phantom{%
    \begin{matrix}#2\end{matrix}}}_{\text{$#1$}}}$}#2}

\begin{document}

Original:
\begin{align}
    \mathbf{W}_{BA} & 
    \begin{pmatrix}
  \vertbar &  & \vertbar & & \vertbar &  & \vertbar  \\
  \mathbf{x}^B_1 & \dots & \mathbf{x}^B_1 & \dots & \mathbf{x}^B_p & \dots & \mathbf{x}^B_p  \\
  \undermat{k}{\vertbar &  & \phantom{--}\vertbar\phantom{--}} & & \undermat{k}{\vertbar &  & {\phantom{--}\vertbar\phantom{--}}}
  \end{pmatrix}
  = \notag \\\\
  & \begin{pmatrix}
  \vertbar &  & \vertbar & & \vertbar &  & \vertbar  \\
  \mathcal{N}(\mathbf{x}^B_1)_1 & \dots & \mathcal{N}(\mathbf{x}^B_1)_k & \dots & \mathcal{N}(\mathbf{x}^B_p)_1 & \dots & \mathcal{N}(\mathbf{x}^B_p)_k  \\
  \undermat{k}{\vertbar &  & \phantom{---}\vertbar\phantom{---}} & & \undermat{k}{\vertbar &  & {\phantom{---}\vertbar\phantom{---}}}
  \end{pmatrix}.
  \\
\end{align}

% Update \vertbar
\renewcommand{\vertbar}[2]{{%
  \setlength{\fboxsep}{.5\fboxsep}
  \ooalign{%
    \hidewidth\rule[-1.5\ht\strutbox]{.4pt}{3.5\ht\strutbox}\hidewidth\cr%
    \colorbox{white}{$#2\strut$}\rule[-1.5\ht\strutbox]{0pt}{3.5\ht\strutbox}%
  }
}}
% Measure some components of the construction
\newlength{\xpB}\settowidth{\xpB}{$\mathbf{x}_p^B$}
\newlength{\NxaB}\settowidth{\NxaB}{$\mathcal{N} \bigl( \mathbf{x}_p^B \bigr)_1$}
\newlength{\NxpB}\settowidth{\NxpB}{$\mathcal{N} \bigl( \mathbf{x}_p^B \bigr)_k$}

Updated:
\begin{align}
  \mathbf{W}_{BA} &
  \Biggl(
    \hspace{0.5\xpB}
    \underbrace{
      \hspace{-0.5\xpB}
      \vertbar{x1B}{\mathbf{x}_1^B} \hspace{0.5em} \cdots \hspace{0.5em} \vertbar{x1B}{\mathbf{x}_1^B}
      \hspace{-0.5\xpB}
    }_k
    \hspace{0.5\xpB}
    \quad \cdots \quad
    \hspace{0.5\xpB}
    \underbrace{
      \hspace{-0.5\xpB}
      \vertbar{xpB}{\mathbf{x}_p^B} \hspace{0.5em} \cdots \hspace{0.5em} \vertbar{xpB}{\mathbf{x}_p^B}
      \hspace{-0.5\xpB}
    }_k
    \hspace{0.5\xpB}
  \Biggr) = \notag \\
  & \Biggl(
    \hspace{0.5\NxaB}
    \underbrace{
      \hspace{-0.5\NxaB}
      \vertbar{Nx1B}{\mathcal{N} \bigl( \mathbf{x}_1^B \bigr)_1} \hspace{0.5em} \cdots \hspace{0.5em} \vertbar{Nx1B}{\mathcal{N} \bigl( \mathbf{x}_1^B \bigr)_k}
      \hspace{-0.5\NxaB}
    }_k
    \hspace{0.5\NxaB}
    \quad \cdots \quad
    \hspace{0.5\NxpB}
    \underbrace{
      \hspace{-0.5\NxpB}
      \vertbar{NxpB}{\mathcal{N} \bigl( \mathbf{x}_p^B \bigr)_1} \hspace{0.5em} \cdots \hspace{0.5em} \vertbar{NxpB}{\mathcal{N} \bigl( \mathbf{x}_p^B \bigr)_k}
      \hspace{-0.5\NxpB}
    }_k
    \hspace{0.5\NxpB}
  \Biggr)
\end{align}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .