# What's the best way to write matrix together with its dimensions on top and left?

I'm trying to show that matrix A (m rows, n columns) times matrix B(n rows, k columns), results as matrix C ( m rows, k columns).

I wonder what's the easier way to write it?

there are several posts here, I found Block matrix equation with dimensioning and Equation with Large Matrix Dimension a bit too complex, while Matrix decomposition dimensions diagram put the dimensions at the bottom of the matrix, while I hope this can be displayed on the left and top.

• @Brian yes. I only know how to put subtext on top-right, top-bottom, top-left, bottom-left corner, but don't know how to put things on top, left, right or bottom. Aug 5, 2014 at 4:00
• Why do you want create confusions when things can be simple and neat? Aug 5, 2014 at 6:02
• I have some experience with linear algebra teaching that, other than showing rectangles with rows and vectors inside them, nothing is illustrative/explanatory. They just create more confusion or state the obvious; People know how to multiply already know it, people who don't know it won't get it with notations. Aug 5, 2014 at 10:42

I would suggest writing something more traditional and clear:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\underset{(m \times n)}{A} \times \underset{(n \times k)}{B} = \underset{(m \times k)}{C}$
\end{document}

• after comparison, I agree, this notation is much better. Thanks! Aug 5, 2014 at 6:27
• I would suggest not using \times between A and B, as the symbol is never used in this context. Aug 5, 2014 at 9:32

You could use the following code -- note the use of positive thinspace (\,) and negative thinspace (\!) to finetune the position of the side-set and supra-set items.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
${}^m\!\overset{\,n}{A} \, {}^n\!\overset{\,k}{B} = {}^m \overset{\,k}{C}$
\end{document}


A variation of Mico's solution, that's less obtrusive.

The height of the two small superscripts can be changed with an optional argument, in case of need:

\rowcol[<height>]{<matrix>}{<rows>}{<columns>}

\documentclass{article}

\newcommand{\rowcol}[4][2ex]{%
\raisebox{#1}{\vtop{
\tiny
\ialign{%
&##\cr
&\rlap{$\,#4$}\cr
\noalign{\nointerlineskip}
$#3\!$\cr
}
}}
#2
}

\begin{document}
$\rowcol{A}{m}{n}\cdot\rowcol{B}{n}{k}=\rowcol{C}{m}{k}$
\end{document}


For a subscript to be put on the top of a given symbol one uses \overset{}{}, where the first blank is to be replaced with the intended subscript and the second blank is to be replaced with the given symbol.

For subscripts to be put on the left or right of a given symbol you may refer to the question here: Left and right subscript / superscript

• Sorry the description is not clear. I just updated the question with a picture. Aug 5, 2014 at 3:51
• Never mind. So do you mean you wish to know the codes for displaying what the picture shows? If so then the revised answer works.
– Yes
Aug 5, 2014 at 4:00

Another suggestion:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$A_{m \times n} B_{n \times k} = C_{m \times k}$
\end{document}


EDIT: Or you can simply declare the matrices

and then AB = C. This notation is used, for example, in Golub, Van Loan, "Matrix Computation", 3rd Ed. Johns Hopkins, 1996.

• How is the suggestion in the edit a decleration of the matirces? You only declare the spaces they are elements in. Jan 15, 2015 at 7:11
• You are formally correct. My suggestion in the edit may be complemented by definition on page 3 of the cited reference. Thank you for your observation.
– user13907
Jan 15, 2015 at 9:13