10

I was trying to explain the identity matrix over at Math StackExchange and I wound up using the following.

$${\bf I_n} = \underbrace{
                \left.\left( 
                      \begin{array}{ccccc}
                             1&0&0&\cdots &0\\
                             0&1&0&\cdots &0\\
                             0&0&1&\cdots &0\\
                             \vdots&&&\ddots&\\
                             0&0&0&\cdots &1
                      \end{array}
                \right)\right\}
              }_{n\text{ columns}} 
              \,n\text{ rows}
$$

It came out alright, but not quite what I wanted:

Identity Matrix

I'd like to be able to move the ends of the underbrace inside the parenthesis without having it turn into this:

Identity Matrix 2

Now, I see there are a couple of similar questions on here (examples: 1 2) which deal with the same issue. However, all of them use a bunch of fancy stuff which I can't use in online forum TeX.

Is there a way to enclose a matrix in braces using only commands available in MathJax?

I am not sure exactly which commands these are, but I am guessing a good rule of thumb would be the simplest commands possible.

1

1 Answer 1

14

This is how I would do it in regular LaTeX (though I would use \[...\] to enclose display math):

$$\mathbf{I}_n = \left.\left( 
                  \vphantom{\begin{array}{c}1\\1\\1\\1\\1\end{array}}
                  \smash{\underbrace{
                      \begin{array}{ccccc}
                             1&0&0&\cdots &0\\
                             0&1&0&\cdots &0\\
                             0&0&1&\cdots &0\\
                             \vdots&&&\ddots&\\
                             0&0&0&\cdots &1
                      \end{array}
                      }_{n\text{ columns}}}
              \right)\right\}
              \,n\text{ rows}
$$

The \vphantom line creates a box whose height is equal to an nx1 array of 1's. The \smash around your matrix typesets the matrix (including the underbrace) but makes its height and depth zero. Put these together and you have a box which includes the underbrace, but whose width and height are equal to that of the matrix without the underbrace.

sample code output

See "A complement to \smash, \llap, and \rlap" by Alexander R. Perlis in TUGBoat for more on all of these commands and also \mathclap.

I pasted it into the MathJax demo page too and it seems to work.

2
  • 2
    It should be \mathbf{I}_{n}, of course: the n shouldn't be bold and \bf is deprecated; \mathbf works in MathJax too.
    – egreg
    Mar 13, 2013 at 1:11
  • @egreg: thanks. I was focusing on the alignment and I didn't notice that. fixed. Mar 13, 2013 at 12:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .