[Tex/LaTex] Typing an 11 x 11 (or larger) Matrix

matrices

I would like to explicitly write out a n x n matrices in my paper, but once n \geq 11, I get compiling errors and it refuses to print the matrix. Here is what I have:

\documentclass{standalone}
\usepackage{amsmath,mathtools,amsthm}
\usepackage{array}

\begin{document}

$$\begin{bmatrix*}[r]
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
-\fract{1}{2} & -\fract{1}{2} & \fract{1}{2}\sqrt{2} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0  & -\fract{1}{2}\sqrt{2} & \fract{1}{2}\sqrt{2} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0  & 0  & -\fract{1}{2}\sqrt{2} & \fract{1}{2}\sqrt{2} & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0  & 0  & 0 & -\fract{1}{2}\sqrt{2} & \fract{1}{2}\sqrt{2}& 0 & 0 & 0 & 0 & 0\\
0 & 0  & 0  & 0 & 0 & -\fract{1}{2}\sqrt{2} & \fract{1}{2}\sqrt{2} & 0 & 0 & 0 & 0\\
0 & 0  & 0  & 0 & 0 & 0 & -\fract{1}{2}\sqrt{2} & \fract{1}{2}\sqrt{2} & 0 & 0 & 0\\
0 & 0  & 0  & 0 & 0 & 0 & 0 & -\fract{1}{2}\sqrt{2} & \fract{1}{2}\sqrt{2}  & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -\fract{1}{2}\sqrt{2} & \fract{1}{2} & \fract{-1}{2}\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1
\end{bmatrix*} $$

\end{document}

I do not see any errors for this 11 x 11 matrix. However, when I type this in a blank standalone document, I get an error that says: "Missing $ inserted. $$\begin{bmatrix*}[r]"

Is there another way to write an 11 x 11 (or larger) matrix so that it compiles? Or is it impossible to type matrices this large into LaTeX? (If it helps, I am using writelatex.com to compile my thesis.)

Best Answer

Summarizing some of my earlier comments:

  • Use the standalone package with the option preview in order to avoid getting an error message about a missing $ symbol.

  • Don't use $$ in a LaTeX document to start and end displaymath mode, as it's quite deprecated. See Why is \[ ... \] preferable to $$ ... $$? for more information on this subject.

  • The matrix environments of the amsmath and mathtools environments work with the counter variable MaxMatrixCols. Its default value is 10; if you have a matrix with, say, 15 columns, issue the instruction \setcounter{MaxMatrixCols}{15}.

  • There is no \fract command; use \frac instead.

For the matrix at hand, I actually wouldn't use any \frac instructions. Instead, I'd use inline-style math notation, i.e., I'd write \sqrt{2}/2, etc. That way, the fractional expressions won't become too tiny to read with ease.

enter image description here

\documentclass[preview]{standalone}
\usepackage{geometry,mathtools}
\setcounter{MaxMatrixCols}{11}
\begin{document}
\[ 
\begin{bmatrix*}[r]
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
-1/2 & -1/2 & \sqrt{2}/2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0  & -\sqrt{2}/2 & \sqrt{2}/2 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0  & 0  & -\sqrt{2}/2 & \sqrt{2}/2 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0  & 0  & 0 & -\sqrt{2}/2 & \sqrt{2}/2& 0 & 0 & 0 & 0 & 0\\
0 & 0  & 0  & 0 & 0 & -\sqrt{2}/2 & \sqrt{2}/2 & 0 & 0 & 0 & 0\\
0 & 0  & 0  & 0 & 0 & 0 & -\sqrt{2}/2 & \sqrt{2}/2 & 0 & 0 & 0\\
0 & 0  & 0  & 0 & 0 & 0 & 0 & -\sqrt{2}/2 & \sqrt{2}/2  & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -\sqrt{2}/2 & 1/2 & -1/2\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1
\end{bmatrix*} 
\]
\end{document}