[Tex/LaTex] Thickness and alignment of curly braces for block matrix dimensions

blockbracesdimensionsmatrices

I need to create block matrices with the dimensions in the right. The blocks of the matrices are of different dimensions.

Here is a MWE:

\documentclass{article}
\usepackage{easybmat}
\usepackage{bm}

\newcommand{\smsub}[1]{\scriptscriptstyle\mathrm{#1}}

\begin{document}

\begin{equation}
  \hat{\bm{P}}=
  \left(
  \begin{BMAT}(b){c}{ccc.c}
    P_{\smsub{1}}  \\ 
    \vdots \\
    P_{\smsub{K-1}}\\
    P_{\smsub{K}}   
  \end{BMAT}
  \right)=
  \left(
  \begin{BMAT}(b){c}{ccc.c}
    \vphantom{\vdots} \\
    \bm{\breve{P}} \\ 
    \vphantom{\vdots} \\
    P_{\smsub{K}}   
  \end{BMAT}
  \right)
  \begin{BMAT}(@)[1pt,10pt,0pt]{l}{cc}
    \left. \vphantom{\rule{0mm}{30pt}}\right\rbrace{\scriptstyle (K-1)\times 1}\\ 
    \left. \vphantom{\rule{0mm}{10pt}}\right\rbrace{\scriptstyle \; 1 \times 1}\\ 
  \end{BMAT}
\end{equation} 

\end{document}

Problems:

  1. I don't know how to create braces with the same thickness. As it can be seen, the upper brace for the (k-1)x1 dimension is larger and sensibly thicker than the one for the lower block. Ideally they should have the same thickness, and they should be thin.

  2. The alignment of the braces added in the third BMAT with the other two BMAT is done somehow manually. Is there a way to align the braces automatically?

I am not tied to use easybmat, so should anybody present a better solution I would be fine with that.

Best Answer

RE-REVISED ANSWER taking insightful suggestion from barbara's comment. Here, as in the immediately prior answer, I use Knuth's \underbrace rotated to make the vertical brace. However, I took barbara's suggestion to make the short brace look better by first making an \underbrace twice as wide as needed, and then squeezing it in half. The net effect is to make the points of the brace more vertically compressed.

The controlling parameters are \hsqz to control the horizontal compression of the brace, and \sqz and its reciprocal \sqzinverse, to control the vertical compression of the brace points. And, as before, bls is empirically matched to the BMAT line spacing, so that the 1st argument to \scalebrace can be given as an integer number of lines, rather than as a length.

\documentclass{article}
\usepackage{easybmat}
\usepackage{bm}
\usepackage{graphicx}
\def\sqz{.5}
\def\sqzinverse{2}
\def\hsqz{.7}
\newcommand{\smsub}[1]{\scriptscriptstyle\mathrm{#1}}
\newlength\bls
\bls=1.5\baselineskip\relax
\newlength\tmplength
\def\scalebrace#1#2{\tmplength=#1\bls\relax%
  \scalebox{\hsqz}[\sqz]{\rotatebox{90}{$\underbrace{\hspace{\sqzinverse\tmplength}}$}}%
  \raisebox{\dimexpr+.5\tmplength+.5\dp\strutbox-.5\ht\strutbox}{$\scriptstyle \; #2$}}
\begin{document}

\begin{equation}
  \hat{\bm{P}}=
  \left(
  \begin{BMAT}(b){c}{ccc.c}
    P_{\smsub{1}}  \\ 
    \vdots \\
    P_{\smsub{K-1}}\\
    P_{\smsub{K}}   
  \end{BMAT}
  \right)=
  \left(
  \begin{BMAT}(b){c}{ccc.c}
    \vphantom{\vdots} \\
    \bm{\breve{P}} \\ 
    \vphantom{\vdots} \\
    P_{\smsub{K}}   
  \end{BMAT}
  \right)
  \begin{BMAT}(@)[1pt,10pt,0pt]{l}{cc}
    \scalebrace{3}{(K-1)\times 1}\\ 
    \scalebrace{1}{1 \times 1}\\ 
  \end{BMAT}
\end{equation} 
\end{document}

enter image description here

REVISED ANSWER (replacing stretched scalerel brace with a rotated \underbrace). The user syntax will be the same as the original answer (e.g., \scalebrace{1}{1 \times 1}), though the resulting brace will look different (and better).

\documentclass{article}
\usepackage{easybmat}
\usepackage{bm}
\usepackage{graphicx}
\newcommand{\smsub}[1]{\scriptscriptstyle\mathrm{#1}}
\newlength\bls
\bls=1.5\baselineskip\relax
\newlength\tmplength
\def\scalebrace#1#2{\tmplength=#1\bls\relax%
  \scalebox{.7}[1]{\rotatebox{90}{$\underbrace{\hspace{\tmplength}}$}}%
  \raisebox{\dimexpr+.5\tmplength+.5\dp\strutbox-.5\ht\strutbox}{$\scriptstyle \; #2$}}
\begin{document}

\begin{equation}
  \hat{\bm{P}}=
  \left(
  \begin{BMAT}(b){c}{ccc.c}
    P_{\smsub{1}}  \\ 
    \vdots \\
    P_{\smsub{K-1}}\\
    P_{\smsub{K}}   
  \end{BMAT}
  \right)=
  \left(
  \begin{BMAT}(b){c}{ccc.c}
    \vphantom{\vdots} \\
    \bm{\breve{P}} \\ 
    \vphantom{\vdots} \\
    P_{\smsub{K}}   
  \end{BMAT}
  \right)
  \begin{BMAT}(@)[1pt,10pt,0pt]{l}{cc}
    \scalebrace{3}{(K-1)\times 1}\\ 
    \scalebrace{1}{1 \times 1}\\ 
  \end{BMAT}
\end{equation} 
\end{document}

enter image description here

The width of the brace is controlled by the argument to \scalebox in the definition of \scalebrace, currently set to .7. Changing that to 1 will give just a plain rotated \underbrace.

ORIGINAL ANSWER:

Here's one way. The scalerel package allows width-limited scales. Thus, when I scale the top right brace to 3 row heights and the bottom right brace to 1 row height, I limit the scaled width of each brace to 1.2ex. In this case, I use the syntax

\scaleleftright[1.2ex]{.}{phantom rule}{\}} ,

where I create the phantom rule with the newly defined \irule that takes an integer number of rows as an argument.

I wrap up the whole shebang inside a macro

\scalebrace{rows}{aftertext}

FYI: The "row height" inside the matrix was empirically determined as 1.5\baselineskip, set in the length \bls.

\documentclass{article}
\usepackage{easybmat}
\usepackage{bm}
\usepackage{scalerel}
\newcommand{\smsub}[1]{\scriptscriptstyle\mathrm{#1}}
\newlength\bls
\bls=1.5\baselineskip\relax
\newlength\tmplength
\def\irule#1{\tmplength=#1\bls\relax%
  \rule[-.5\tmplength-.5\dp\strutbox+.5\ht\strutbox]{0ex}{\tmplength}}
\def\scalebrace#1#2{%
  \scaleleftright[1.2ex]{.}{\irule{#1}}{\}}{\scriptstyle \; #2}}
\begin{document}

\begin{equation}
  \hat{\bm{P}}=
  \left(
  \begin{BMAT}(b){c}{ccc.c}
    P_{\smsub{1}}  \\ 
    \vdots \\
    P_{\smsub{K-1}}\\
    P_{\smsub{K}}   
  \end{BMAT}
  \right)=
  \left(
  \begin{BMAT}(b){c}{ccc.c}
    \vphantom{\vdots} \\
    \bm{\breve{P}} \\ 
    \vphantom{\vdots} \\
    P_{\smsub{K}}   
  \end{BMAT}
  \right)
  \begin{BMAT}(@)[1pt,10pt,0pt]{l}{cc}
    \scalebrace{3}{(K-1)\times 1}\\ 
    \scalebrace{1}{1 \times 1}\\ 
  \end{BMAT}
\end{equation} 
\end{document}

enter image description here