2

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?

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*).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.