[Tex/LaTex] Enforcing That \array Stays Square When Drawing Matrix

arraysmath-modematrices

I'm trying to draw a block matrix in LaTeX, and this is what I have so far:

\begin{array}{|c|c|}
    \hline
    I_{r \times r} & 0 \\
    \hline
    0 & 0 \\
    \hline
\end{array}

Here's a picture of what this looks like when rendered:

enter image description here

How would I enforce that the matrix be square when rendered? Right now, it's clearly wider than it is tall because of the I_{r \times r} placed in top-left element. Also, the intersections of the lines at the corners of the matrix are not being rendered properly. Do you have any suggestions as to how I could fix this as well?

Best Answer

the width/height of a cell is a parameter of the columntype C

\documentclass{article}
\usepackage{array}
\newcolumntype{C}[1]{@{}>{\rule[0.5\dimexpr-#1+1.2ex]{0pt}{#1}\hfil$}p{#1}<{$\hfil}@{}}
\begin{document}     
\Huge
$\begin{array}{|C{2cm} | C{2cm} |}\hline
  I_{r \times r} & 0 \\\hline
               0 & 0 \\\hline
\end{array} $ 
$\begin{array}{|C{2.5cm} | C{2.5cm} |}\hline
  I_{r \times r} & 0 \\\hline
               0 & 0 \\\hline
\end{array} $ 
\end{document}

enter image description here