How to create the matrix attached that has 2x2 blocks in its diagonal and a square outlining them?

I am struggling to create the matrix in the picture attached using Latex. I have tried using commands like \hline but the matrix ends up looking messy as the line goes all the way across.

Edit: To clarify, I am looking for each block to have a square outline.

• Welcome. Please add a minimal working example (MWE) and see the TeX.SX starter guide when asking a question. So that people have a starting point. – BambOo Apr 15 '18 at 15:33
• Use TikZ's \matrix: each entry is itself a node, so it is possible to draw (A-1-1.north west)rectangle(A-2-2.south eaast). – Symbol 1 Apr 15 '18 at 16:01

Is this like you want?

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

\begin{document}

\setlength{\fboxsep}{0pt}%\setlength{\arraycolsep}{0pt} \left(\begin{array}{@{}c@{}c@{}c@{\mkern-5mu}c@{\,}cc*{2}{@{\;}c}@{}}% \noalign{\vskip 1.5ex} \fbox{\,\begin{matrix} 0 & 1 \\ -1 & 0 \end{matrix}\,} \\[-0.4pt] & \hskip-0.4pt\fbox{\,\begin{matrix} 0 & 1 \\ -1 & 0 \end{matrix}\,}\\[-0.5ex] & & \;\ddots \\[-2.2ex] & & & \;\ddots \\[-0.5ex] & & & & \fbox{\,\begin{matrix} 0 & 1 \\ -1 & 0 \end{matrix}\,}\\ & & & & &0 \\[-1.5ex] & & & & & & \ddots \\[-1ex] & & & & & & & 0 \bigstrut[b] \end{array}\right)

\end{document}


Edit: or even this variant:

\setlength{\fboxsep}{0pt}%\setlength{\arraycolsep}{0pt} \left(\begin{array}{@{}c@{}l@{}c@{\mkern-5mu}c@{\,}rc*{2}{@{\;}c}@{}}% \noalign{\vskip 1.5ex} \fbox{\,\begin{matrix} 0 & 1 \\ -1 & 0 \end{matrix}\,} \\[-0.4pt] & \hskip-0.4pt\fbox{\,\begin{matrix} 0 & 1 \\ -1 & 0 \end{matrix}\,} & & & \text{\LARGE 0} \\[-0.5ex] & & \;\ddots \\[-2.2ex] & & & \;\ddots \\[-0.5ex] &\text{\LARGE 0} & & & \fbox{\,\begin{matrix} 0 & 1 \\ -1 & 0 \end{matrix}\,}\\ && & & &0 \\[-1.5ex] & & & & & & \ddots \\[-1ex] & & & & & & & 0 \bigstrut[b] \end{array}\right)


Do you need something like this only, or do you also want the box around the blocks ?

\documentclass{article}
\usepackage{amsmath}
\begin{document}

$$\begin{bmatrix} 0 & 1 & & & & & & &\\ -1 & 0 & & & & & & &\\ & & 0 & 1 & & & & & \\ & & -1 & 0 & & & & & \\ & & & & \ddots & & & \\ & & & & & 0 & 1 & & & \\ & & & & & -1 & 0 & & & \\ & & & & & & & 0 & & \\ & & & & & & & & \ddots & \\ & & & & & & & & & 0\\ \end{bmatrix}$$

\end{document}