[Tex/LaTex] How to draw the following matrix in LaTeX

tikz-matrix

I want to draw the following matrix in LaTeX:

Enter image description here

I found that I should use the TikZ package, and I have spent a lot of time looking at the package. However, I have no experience of using the package before, and I do not know how to draw it. How can I do it?

Best Answer

Just arrays:

\documentclass{article}
\usepackage{amsmath,array}

\begin{document}

\[
\newcommand{\blocke}{
  \begin{matrix}
  \hphantom{0} & \hphantom{0} & \hphantom{0} & \hphantom{0} \\
  \\ \\
  \end{matrix}
}
\newcommand{\blockr}{
  \begin{matrix}
  \hphantom{0} & \hphantom{0} & \hphantom{0} &
  \hat{N}\smash[b]{\vphantom{\Big|}} \\ &&& \vdots \\ &&& 2 \\ &&& 1
  \end{matrix}
}
\newcommand{\blockl}{
  \begin{matrix}
  1 & \hphantom{0} & \hphantom{0} & \hphantom{0} \\
  2 \\ \vdots \\ \hat{N}\smash[b]{\vphantom{\Big|}}
  \end{matrix}
}
\newcommand{\dddots}{
  \begin{matrix}
  \hphantom{0} & \hphantom{0} & \ddots \\
  \\
  \\
  \ddots
  \end{matrix}
}
\begin{pmatrix}
\hspace*{0.3em}
\begin{array}{|*{5}{@{\,}c@{\!}|}}
\hline
& \blockl & & & \blocke \\
\hline
\blockr & & \blockl & & \\
\hline
& \blockr & & \blockl & \\
\hline
& & & \dddots & \\
\hline
& & & \blockr & \\
\hline
\end{array}
\hspace*{0.3em}
\end{pmatrix}
\]

\end{document}

I locally defined a few commands to ease input.

enter image description here