6

I need to typeset the following matrix

enter image description here

but I'm having trouble understanding the nicematrix package. I am trying to write it like this

    \begin{document}
    \begin{align*}
    \begin{pNiceArray}{cccc|ccc}
      \Block{2-2}<\Large>{\mathbf{S}}  & \Block{2-2}<\Large>{\mathbf{0}}  \\
      0 & A & -A & 0 \\
      \hline
      \Block{2-2}<\Large>{\mathbf{0}} && A & 0 & A
    \end{pNiceArray}
    \end{align*}
    \end{document}
If you can give me any help I'll be grateful.
Alex
  • 63
  • Welcome to TeX.SE. – Mico Jan 21 '24 at 12:48
  • Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for the users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – samcarter_is_at_topanswers.xyz Jan 21 '24 at 12:51
  • Is there a reason you place S in a block in your code? Do you want S to have an arbitrary number of columns? – Sandy G Jan 21 '24 at 14:11
  • No, S is a fixed matrix. – Alex Jan 21 '24 at 14:20

2 Answers2

7

Here is a possibility using nicematrix. The option hvlines creates the horizontal and vertical rules and respects the blocks.

enter image description here

\documentclass{article}

\usepackage{nicematrix}

\begin{document}

[ \begin{pNiceMatrix}[hvlines] S & -A & \Block{1-2}{0} &\ \Block{2-1}{0} & A & -A & 0\ & A & 0 & -A \end{pNiceMatrix} ]

\end{document}

Sandy G
  • 42,558
6

Here's an array-based solution.

enter image description here

\documentclass{article} 
\usepackage{array}     % for '\extrarowheight' macro
\usepackage{multirow}  % for '\multirow' macro

\begin{document}

\begingroup % localize scope of the next instruction \Large % '\Large' is a textmode command [ \setlength\extrarowheight{2pt} \left( \begin{array}{ l | c | c | c } S & -A & \multicolumn{2}{c}{0} \ \hline \multirow{2.1}{*}{0} & A & -A & 0 \ \cline{2-4} & A & 0 & -A \end{array} \right) ] \endgroup

\end{document}

Mico
  • 506,678
  • Thank you, is it wrong to enclose my matrix code in align as I did? Should I prefer to just use [ ]? Also: is there a way to communicate the idea that the zero blocks are of course of different dimensions? – Alex Jan 21 '24 at 12:51
  • 1
    @Alex - I would not use an align* environment as there's nothing to align. I suppose you could use \begin{equation*} and \end{equation*} if, for some reason, you're not comfortable with \[ and \]. – Mico Jan 21 '24 at 12:53
  • @Alex - Whoever reads your paper better be aware of the fact that the submatrices can be either square or non-square, depending on the situation. If there's any chance that readers don't "get" this, I wouldn't use the current notation. Instead, I'd write 0 twice in row 1 and once each at the start of rows 2 and 3. – Mico Jan 21 '24 at 12:56
  • 3
    @Alex - Please also familiarize yourself with the posting What are the differences between $$, \[, align, equation and displaymath [shameless self-citation alert!] – Mico Jan 21 '24 at 12:58
  • Thanks for both of your suggestions. Would it be very hard to add something like a brace above the big zero block to specify the dimension? – Alex Jan 21 '24 at 13:18
  • 1
    @Alex - Assiuming k is the number of rows/columns of the square matrices, I'd change the upper-right zero matrix from 0 to 0_{\scriptscriptstyle k\times 2k}; similarly, I'd change the lower-left zero matrix from 0 to 0_{\scriptscriptstyle 2k\times k} – Mico Jan 21 '24 at 14:31