Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would I create an output similar to the result produced by this LaTeX code:

M = \bordermatrix{~ & x & y \cr
                  A & 1 & 0 \cr
                  B & 0 & 1 \cr}

which when compiled, looks like

enter image description here

share|improve this question
up vote 8 down vote accepted

This seems to work, at least for your example:

TraditionalForm @ Grid[{{Null, Grid[{{x, y}}]}, {TableForm@{{A}, {B}}, 

enter image description here

You can make a little function that generalises it:

makeBordermatrix[mat_?MatrixQ, top_?VectorQ, side_?VectorQ] := 
  Grid[{{Null, Grid[{top}]}, {TableForm[Transpose@{side}], 

So we have:

makeBordermatrix[IdentityMatrix[3], {x, y, z}, {A, B, C}]

enter image description here

share|improve this answer
By the way, welcolme to Mathematica.SE James! – Verbeia Apr 26 '12 at 5:08
Ah nice, I didn't quite manage to get TraditionalForm to give it this way – R. M. Apr 26 '12 at 5:12
This isn't very robust, though: try makeBordermatrix[IdentityMatrix[3] {aaaaaaaaaa, 0, 0}, {x, y, z}, {A, B, C}] and the columns get misaligned. To fix this, you could make each element of the top row have an Overlay in which all matrix entries below it are stacked on top of each other with Opacity[0], to force the top row to accomodate the maximum width of the row. – Jens Apr 26 '12 at 6:53
@Jens I know, I didn't enforce matching dimensions or lengths of objects (limited lunch break time), but it would be straightforward to do. – Verbeia Apr 26 '12 at 6:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.