12

I want to write code for a matrix of the form given in the picture below. How can I do it?

matrix

What I have tried is the following code:

\begin{bmatrix} 
     a &      r &      0 & \dots \\  
     r &      b &      s & \dots \\ 0 & s & 0 &  \dots \\
\vdots & \vdots & \vdots & \LARGE{D} \\ 
\end{bmatrix}

which, needless to say, is ugly. Can anyone please help me out?

3
  • Welcome to TeX.SE.
    – Mico
    Commented May 6, 2023 at 20:54
  • Aside: \LARGE is a text-mode command and doesn't work as expected when used in math mode.
    – Mico
    Commented May 6, 2023 at 21:05
  • This might help: How to write the given block matrix Commented May 6, 2023 at 21:07

2 Answers 2

14

I suggest you employ an array environment inside a \left[ ... \right] "wrapper". If you think the letter "D" needs to be enlarged a bit, I suggest you do so with the help of the \scalebox macro (provided by the graphicx package).

The following screenshot shows two ways how these suggestions may be implemented. The one on the left is conceptually simpler, as it employs just one array environment. The one on the right is able to achieve perfect vertical (as well as horizontal) centering of the large letter "D" because it employs nested array environments as well as the TeX-primitive directive \vcenter.

enter image description here

\documentclass{article} 
\usepackage{array}
\usepackage{graphicx} % for '\scalebox' macro
\usepackage{newtxtext,newtxmath} % optional: Times Roman text and math fonts

\begin{document}
\[
\left[ \begin{array}{cc|cccc}
   a & r & 0 & 0 & \dots & 0 \\
   r & b & s & 0 & \dots & 0 \\ 
   \hline
   0 & s & \\
   0 & 0 & \\
   \vdots & \vdots & \multicolumn{4}{c}{%
      \smash{\scalebox{2}{$D$}}} \\
   0 & 0 & \\
\end{array} \right]
\qquad 
\left[ \begin{array}{cc|cccc}
   a & r & 0 & 0 & \dots & 0 \\
   r & b & s & 0 & \dots & 0 \\ 
   \hline
   \multicolumn{2}{c|}{%
     \begin{array}{@{} cc @{}}
       0 & s \\
       0 & 0 \\
       \vdots & \vdots \\
       0 & 0 
     \end{array}
   } &
   \multicolumn{4}{c}{%
     \begin{array}{@{} c @{}}
       \vcenter{\hbox{\scalebox{2}{$D$}}}
     \end{array}
   }
\end{array} \right]
\]
\end{document}
1
  • Thanks for your quick answer(+1) Commented May 6, 2023 at 21:14
13

With nicematrix package:

\documentclass[margin=3mm]{standalone}
\usepackage{nicematrix}

\begin{document}

$\begin{bNiceArray}{cc|c ccc}[margin]
  a    & r      & 0 & 0 & \Cdots & 0    \\
  r    & b      & s & 0 & \Cdots & 0    \\
\hline
  0    & s      & \Block{3-4}<\huge>{D} \\
\Vdots  &\Vdots                         \\
  0     & 0
\end{bNiceArray}$
\end{document}

After at least two compilation you will get:

enter image description here

Edit: Now in matrix code is considered @Mico and my comments below.

3
  • @Mico, termination of the last row is superfluous (removed now). In this particular case I also could skip ampersands in ara of block. I do not understand which zeros I should skip.
    – Zarko
    Commented May 7, 2023 at 5:36
  • @Mico, I see now. In my previous comment I mentioned this with other words. I will consider this in my answer.
    – Zarko
    Commented May 7, 2023 at 6:01
  • Huh, @Mico you are right again. I lost termination of matrix row with \bloc . Now is added and MWE can be compiled without error. It gives showed matrix image.
    – Zarko
    Commented May 7, 2023 at 7:52

You must log in to answer this question.

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