4

I have a matrix

\documentclass{standalone}
\usepackage{amsmath}
$
P= 
\begin{pmatrix}
0 & \gamma & \gamma & \gamma \\
0 & -2\tau -\gamma & 0& 0 \\
0 & 0 & -2\tau-\gamma & 0\\
0&0&0&-2\tai-\gamma
\end{pmatrix}
$

Which looks likea matrix. It has some submatrices we can identify.

\documentclass{standalone}
\usepackage{amsmath}
$
P = 
\begin{pmatrix}
%
\begin{pmatrix} 0 \end{pmatrix}  & 
\begin{pmatrix} \gamma & \gamma & \gamma\end{pmatrix} \\
%
%
\begin{pmatrix} 0\\ 0\\ 0 \end{pmatrix} & 
\begin{pmatrix}-2\tau -\gamma & 0& 0\\  
                         0 & -2\tau -\gamma & 0\\
                         0 & 0 & -2\tau -\gamma 
\end{pmatrix} 
\end{pmatrix}
$

So that it looks likenew matrix with sub-blocks.

But the columns don't line up between the submatrices, and the parentheses overlap. Fixing the parentheses should be easy by just adding a bit more space between lines, but I haven't found a good way to control the columns.

I'm looking for a good option to fix this. I'd prefer to stick to \pmatrix if possible. Is it possible to use pmatrix so that the columns align?

3 Answers 3

4

You can insert the \gamma elements inside a box of width -2\tau-\gamma so they take up the same space horizontally as needed:

enter image description here

\documentclass{article}

\usepackage{amsmath,calc}

\begin{document}

\[
  P = 
  \begin{pmatrix}
    %
    \begin{pmatrix} 0 \end{pmatrix}  & 
    \begin{pmatrix}
      \makebox[\widthof{$-2\tau-\gamma$}]{$\gamma$} & 
      \makebox[\widthof{$-2\tau-\gamma$}]{$\gamma$} & 
      \makebox[\widthof{$-2\tau-\gamma$}]{$\gamma$}
    \end{pmatrix} \\[.5\normalbaselineskip]
    %
    \begin{pmatrix} 0 \\ 0 \\ 0 \end{pmatrix} & 
    \begin{pmatrix}
      -2\tau -\gamma & 0 & 0 \\
      0 & -2\tau -\gamma & 0 \\
      0 & 0 & -2\tau -\gamma 
    \end{pmatrix} 
  \end{pmatrix}
\]

\end{document}

I've emphasized a gap between the first and second row; something you can tweak to suit your needs.

3

The package nicematrix has tools designed to address that kind of problem.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$P = \begin{pNiceArray}[margin]{c@{\qquad}ccc}
  0 & \gamma & \gamma & \gamma \\
  0 & -2 \tau - \gamma & 0 & 0 \\
  0 & 0 & -2 \tau - \gamma & 0 \\
  0 & 0 & 0 -2 \tau - \gamma 
\CodeAfter [sub-matrix/extra-height=-1pt]
  \SubMatrix({1-1}{1-1})
  \SubMatrix({1-2}{1-4})
  \SubMatrix({2-1}{4-1})
  \SubMatrix({2-2}{4-4})
\end{pNiceArray}$

\end{document}

Output of the above code

2

Here is a solution with the blkarray package and some fine-tuning:

\documentclass{article}
\usepackage{mathtools}
\usepackage{blkarray}

\begin{document}

$ P =
\begin{pmatrix}
  \begin{blockarray}{c ccc}%
  \BAnoalign{\vspace*{-2ex}}
  \begin{block}{(c)@{\hspace*{1em}}(ccc)}
  0 & \gamma & \gamma & \gamma \\
  \end{block}
  \begin{block}{(c)@{\hspace*{1.333em}} (ccc)}%
  \BAnoalign*{\vspace*{-2ex}}
  0 & -2\tau -\gamma & 0 & 0 \\
  0 & 0 & \mathclap{-2\tau -\gamma} & 0 \\
  0 & 0 & 0 & -2\tau -\gamma \\
  \end{block}
  \BAnoalign{\vspace*{-5ex}}
  \end{blockarray}%
\end{pmatrix} $

\end{document} 

enter image description here

You must log in to answer this question.

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