Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Related: Curly brackets around a table –  Qrrbrbirlbel Mar 14 '13 at 0:38
add comment

1 Answer

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.

share|improve this answer
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 '13 at 1:11
    
@egreg: thanks. I was focusing on the alignment and I didn't notice that. fixed. –  Matthew Leingang Mar 13 '13 at 12:14
add comment

Your Answer

 
discard

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.