Matrix format in Latex

How can a matrix be written in LaTeX? I have tried to use \begin{matrix} but I need to write the matrix below and I cannot understand how to fill it up exactly as this.

• \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{matrix} should work
– user31729
Commented May 22, 2015 at 17:57
• Basic guidelines are at the LaTeX wiki.
– DJP
Commented May 22, 2015 at 18:02
• I have already seen those but I am getting a lot of missing $etc Commented May 22, 2015 at 18:03 • @user1930901: You have to wrap a math environment around \begin{matrix}...\end{matrix}, say$...\$ or $$...$$ of course
– user31729
Commented May 22, 2015 at 18:07
• You can also use the pmatrix environment. Commented May 22, 2015 at 18:10

MWE:

\documentclass[11pt]{article}
\usepackage{amsmath}

\begin{document}
\begin{equation*}
Q =
\begin{pmatrix}
-(\lambda_1 + \mu_1) & \lambda_1 & 0 & \ldots & 0 & 0 \\
0 & -(\lambda_2 + \mu_2) & \lambda_2 & \ldots & 0 & 0 \\
\vdots & \vdots & \vdots & \ldots & 0 & 0 \\
0 & 0 & 0 & -(\lambda_{n-1} + \mu_{n-1}) & \lambda_{n-1} & \\
0 & 0 & 0 & \ldots & 0 & -\mu_n
\end{pmatrix}
\end{equation*}
\end{document}


• Thanks! can you label such equation? since I did \label{2} before but nothing is showing Commented May 22, 2015 at 18:11
• @user1930901 use the unstarred version: , not \begin{equation*}.
– Null
Commented May 22, 2015 at 18:13