# How to have a matrix aligned with the rest of an equation?

When I include a matrix in an equation, the first part of the equation is separated off to the left of the page, while the matrix is spaced away in its own centred area on its own line. Here is what I am currently doing:

$M^{-T} = \frac{1}{|det(M)|} \begin{bmatrix} a_{22} & - a_{21} \\ -a_{12} & a_{11} \end{bmatrix}$


What is the correct approach for this?

-
Welcome to TeX.SX! Remove those $ symbols: you're getting an error message for that. – egreg Feb 14 '12 at 20:31 Should it be M^{-T} or M^{-1} on the LHS of the equation? – Mico Feb 14 '12 at 21:31 add comment ## 1 Answer The notation $ and $ puts TeX in (display) math mode, meaning you don't have to enter math mode again using $ ... \$. In fact, this causes an error. Barring that, the alignment should be fine:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
$M^{-T} = \frac{1}{|\det(M)|} \begin{bmatrix} \phantom{-}a_{22} & -a_{21} \\ -a_{12} & \phantom{-}a_{11} \end{bmatrix}$
\end{document}​


In the above example I've played around with some parameters:

• Right-aligned all the entries in the bmatrix (using \phantom) so positive and negative scalar quantities line up. This may be personal preference.
• amsmath provides \text which sets its argument in the correct font size (although it doesn't matter in your specific case) in text mode. You'll notice a difference in the spacing between det and \text{det} in math mode. Moreover, in math mode, det is intepreted as d multiplied by e, multiplied by t, which is not correct. LaTeX also provides \det natively for this, defined as a math operator (and therefore has a marginally different spacing, but better in general).
-
The \text lesson is a good one, but amsmath also provides \det directly. –  Ryan Reich Feb 14 '12 at 20:40
@RyanReich: Thanks! Forgot about that. –  Werner Feb 14 '12 at 20:43
@Werner In any case \operatorname should be used, not \text, if the operator is not predefined. Of course you can predefine it with \DeclareMathOperator. –  egreg Feb 14 '12 at 20:48
@egreg: Speaking of which: am I the only one who sets a shorthand \on = \operatorname and just doesn't bother with \DeclareMathOperator at all? –  Ryan Reich Feb 14 '12 at 20:58
@RyanReich When an operator is used several times, I find it clearer to define a command. For a couple of applications, \operatorname is not a problem. That's me, of course. –  egreg Feb 14 '12 at 21:20
show 1 more comment