3

I have written a fairly standard matrix as an array since I wanted to have a matrix within it. Typeset as follows:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{array}
\usepackage{multirow}
\def\block(#1,#2)#3{\multicolumn{#2}{c}{\multirow{#1}{*}{$ #3 $}}}
\begin{document}
\[A =
    \left(
    \begin{array}{cccccc|cc}
    1 & 1 &   &   &   &   &   &   \\
    1 & 0 & 1 &   &   &   &   &   \\
      & 1 & 0 & \ddots &   &   &   &   \\
      &   & \ddots & \ddots & 1 &   &   &   \\  
      &   &   & 1 & 0 & 1 &   &   \\  
      &   &   &   & 1 & 0 & 1 &   \\ 
    \hline
      &   &   &   &   & 1 & \block(2,2){M} \\
      &   &   &   &   &   &  \\ 
    \end{array}
    \right)
\]
\end{document}

Weird spacing in matrix

Annoyingly, there's extra spacing between some of the columns and rows: in particular, the second & third column and second & third row. Also seems like there's some issues between the third-to-last & second-to-last column in the top left matrix, though I'm not sure if that's because of \ddots.

Any ideas why this is happening and how I could potentially fix it?

2 Answers 2

4

An easy workaround is to remove the \ddots' width and height, although there may be better ways.

\documentclass{article}

\usepackage{amsmath}
\usepackage{array}
\usepackage{multirow}
\usepackage{mathtools}

\def\block(#1,#2)#3{\multicolumn{#2}{c}{\multirow{#1}{*}{$ #3 $}}}

\makeatletter
    \def\smashddots{%
        \let\@old@ddots\ddots
        \def\ddots{\mathclap{\smash{\@old@ddots}}}%
    }
\makeatother

\begin{document}

\[\smashddots
    A =
    \left(
    \begin{array}{cccccc|cc}
        1 & 1 &   &   &   &   &   &   \\
        1 & 0 & 1 &   &   &   &   &   \\
          & 1 & 0 & \ddots &   &   &   &   \\
          &   & \ddots & \ddots & 1 &   &   &   \\  
          &   &   & 1 & 0 & 1 &   &   \\  
          &   &   &   & 1 & 0 & 1 &   \\ 
        \hline
          &   &   &   &   & 1 & \block(2,2){M} \\
          &   &   &   &   &   &  \\ 
    \end{array}
    \right)
\]

\end{document}

MWE output

You may also be interested in this modification of \env@matrix, which allows you to specify columns when using e.g. pmatrix (or you could use mathtools' pmatrix*).

1

With {pNiceArray} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}
\NiceMatrixOptions{nullify-dots,xdots/shorten=6pt}

\begin{document}

\[  \renewcommand{\arraystretch}{1.3}
    A =
    \begin{pNiceArray}{cccccc|cc}[margin=2pt]
        1 & 1 \\
        1 & 0 & 1 \\
          & 1 & 0 & \Ddots \\
          &   & \Ddots & \Ddots & 1 \\
          &   &   & 1 & 0 & 1 \\
          &   &   &   & 1 & 0 & 1 &   \\ 
        \hline
          &   &   &   &   & 1 & \Block{2-2}{M} \\
          \\
    \end{pNiceArray}
\]

\end{document}

Output of the above code

You must log in to answer this question.

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