3 Answers
3

Here I do it with stacks, setting the indices below the boxes. The primary macro is

\matbox{rows}{columns}{row index}{column index}{matrix name}.

A helper macro is \raiserows, which is like a \raisebox, except that the "length" is specified in rows, not actual length. Note that in the MWE, because X has 7 rows, while P^T only has 2 rows, P^T must be lifted (7-2)/2 = 2.5 rows.

I introduce the factor \matscale to scale your box sizes. By default, each row and column of the box size will occupy a square of size \baselineskip on a side. The factor \matscale (which defaults to 1) will scale that value.

I didn't have 'stackengine' package installed by default on macTeX, so I needed sudo tlmgr install stackengine
–
MemmingMar 27 '14 at 17:42

1

@Memming The package is almost a year old, but that still might not make it to some older installations. Thanks for figuring it out, since I couldn't help you with mactex.
–
Steven B. SegletesMar 27 '14 at 18:00

@Memming if you used MacTeX to install tex on you Mac, it comes with Tex Live Utility which is a great tool to update packages via a graphic user interface.
–
jfbuMar 27 '14 at 20:47

Obviously this doesn't compare to Mr. Segletes's powerful and general answer! It does use more basic commands, however, which could have the benefits that it's quicker to compile on a slow machine, and it will work even with a smaller installation that's lacking in packages. Or perhaps you just like getting your hands dirty. The drawback, of course, is that you have to determine all the widths, heights, and depths yourself.

Note: if you use mathtools or any other package that provides a \clap command, it will conflict with the definition. In this case, just omit this definition and use the \clap provided.