# How can I create a matrix normal form?

Is it possible to create a matrix like the following draft with LaTeX?

I have found this Tikzample, but I don't know how to get the dots on the diagonal.

edit: This is how far I got:

$$\begin{pmatrix} 1 & & & & & & & & & \\ & & & & & & & & & \\ & & 1 & & & & & & & \\ & & & -1 & & & & & & \\ & & & & & & & & & \\ & & & & & - 1 & & & & \\ & & & & & & cos \omega_1 & -sin \omega_1 & & \\ & & & & & & sin \omega_1 & cos \omega_1 & & \\ & & & & & & & & & \\ & & & & & & & & & cos \omega_2 \\ & & & & & & & & & sin \omega_2 \\ \end{pmatrix}$$


The lime part is what I would like to have, but wasn't able to do with LaTeX.

-
Can you provide your code without the dots? – percusse Jun 20 '12 at 16:19
Possible duplicate of tex.stackexchange.com/questions/47765/… which is duplicate of tex.stackexchange.com/questions/40028/… – Ichibann Jun 20 '12 at 17:18
If you write \sin and \cos -- note the backslash characters -- you'll get upright roman lettering for the sine and cosine functions, rather than the differently-spaced math italics that result if you type sin and cos without the backslash characters. – Mico Jun 20 '12 at 17:22
@Ichibann: I don't think the new question is a duplicate -- the older question you reference doesn't have the blank spaces off the (block) diagonal of the matrix that are required in the new question. – Mico Jun 20 '12 at 17:23
@Mico, but blank spaces are the easiest part assuming you already have those borders. – Ichibann Jun 20 '12 at 17:47

If you need the vertical and horizontal lines around the matrix blocks, the following solution (which also doesn't require TikZ) may be of interest. (I've updated the example to reflect the update in your question, which appears to require an extra \ddots row/column.)

Note that I use the array environment rather than the matrix (or pmatrix) environment as it's necessary to right-align the contents of some columns.

\documentclass{article}
\usepackage{amsmath,array}
\renewcommand\arraycolsep{4pt} % default value: 6pt
% short-hand commands for multicolumn entries with vertical bar
% on left and right hand sides, respectively
\newcommand{\mcl}[1]{\multicolumn{1}{|r}{#1}}
\newcommand{\mcr}[1]{\multicolumn{1}{r|}{#1}}
\begin{document}
\begin{equation*}
\left( \,\begin{array}{rcr rcr rr c rr}
\cline{1-3}
\mcl{1} &        & \mcr{}  \\
\mcl{}  & \ddots & \mcr{}  \\
\mcl{}  &        & \mcr{1} \\
\cline{1-6}
& & & \mcl{-1} &        & \mcr{}  \\
& & & \mcl{}   & \ddots & \mcr{}  \\
& & & \mcl{}   &        & \mcr{-1}\\
\cline{4-8}
& & & & & & \mcl{\cos \omega} & \mcr{-\sin \omega}\\
& & & & & & \mcl{\sin \omega} & \mcr{ \cos \omega}\\
\cline{7-8}
& & & & & & & & \ddots\\
\cline{10-11}
& & & & & & & & & \mcl{\cos \omega} & \mcr{-\sin \omega}\\
& & & & & & & & & \mcl{\sin \omega} & \mcr{ \cos \omega}\\
\cline{10-11}
\end{array}\,\right)
\end{equation*}
\end{document}


Addendum: Using the \boxed macro, the code that sets up this matrix can be simplified considerably:

\documentclass{article}
\usepackage{amsmath,array}
\renewcommand\arraycolsep{4pt} % default value: 6pt
\begin{document}
\begin{equation*}
\left( \,
\begin{array}{r@{}r@{}r r r}  % @{} is used twice to suppress intercolumn whitespace
\boxed{ \begin{array}{rrr}              % First block
1 \\
& \ddots\\
& & 1 \\
\end{array} } \\
& \boxed{ \begin{array}{rrr}            % Second block
-1 \\
& \ddots\\
& & -1\\
\end{array} } \\
& & \boxed{ \begin{array}{rr}           % Third block
\cos \omega & -\sin \omega\\
\sin \omega &  \cos \omega\\
\end{array} } \\
& & & \ddots\\                          % Fourth "block" -- not boxed
& & & & \boxed{ \begin{array}{rr}       % Fifth block
\cos \omega & -\sin \omega\\
\sin \omega &  \cos \omega\\
\end{array} } \\
\end{array}\,\right)
\end{equation*}
\end{document}


-

You can use the excellent code from Stefan : (personally I prefer tikz's code )

\documentclass{article}
\usepackage{tikz,amsmath}

\usetikzlibrary{fit,matrix}
\tikzset{%
highlight/.style={rectangle,rounded corners,fill=red!15,draw,fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][submatrix]{%
\tikz[overlay,remember picture]{
\node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\begin{document}​
$M = \left(\begin{array}{*5{c}} \tikzmark{left}{1} & 2 & 3 & 4 & 5\\ 6 & \ddots & 8 & 9 & 10 \\ 11 & 12 & \ddots\tikzmark{right}{} & 14 & 15 \\ 16 & 17 & 18 & \ddots & 20 \\ 0 & 0 & 0 & 0 & 1 \end{array}\right) \Highlight[first]$

\end{document}​


Something more complex :

\documentclass{article}
\usepackage{tikz,amsmath}

\usetikzlibrary{fit,matrix}
\tikzset{%
highlight/.style={rectangle,fill=#1!15,draw,fill opacity=0.5,thick,inner sep=1pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline=(#1.base)] \node (#1) {#2};}

\newcommand{\Highlight}[3]{%
\tikz[overlay,remember picture]{
\node[highlight=#3,fit=(#1.north west) (#2.south east)]  {};}
}
\begin{document}​

\begin{equation*}
\begin{pmatrix}
\tikzmark{1}{c}  &  -a              &  0    & \dots  & \dots  & \dots                &  0 \\
-b & \tikzmark{2}{c}  & -a    & \ddots &        &                      & \vdots \\
0 &  -b              & \tikzmark{3}{c}    & \ddots & \ddots  &        & \vdots \\
\vdots & \ddots           & \ddots & \ddots & \ddots & \ddots              & \vdots \\
\vdots &                  & \ddots & \ddots &   c    &  -a                 &  0 \\
\vdots &                  &        & \ddots &  -b    &    \tikzmark{4}{c}  & -a \\
0 & \dots            & \dots  & \dots  &   0    &  -b                 &  c
\end{pmatrix}
\end{equation*}
\Highlight{1}{2}{blue}
\Highlight{3}{4}{red}

\end{document}​


-

If you use the amsmath package you can do it without tikz:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$\begin{pmatrix}1&&&&&&&&&\\ &\ddots&&&&&&&&\\ &&1&&&&&&&\\ &&&-1&&&&&&\\ &&&&\ddots&&&&&\\ &&&&&-1&&&&\\ &&&&&&\cos w&-\sin w&&\\ &&&&&&\sin w&\cos w&&\\ &&&&&&&&\cos w&-\sin w\\ &&&&&&&&\sin w&\cos w\\\end{pmatrix}$


or with those boxes, if you need them:

    $\begin{pmatrix} \boxed{\begin{matrix} 1&&\\ &\ddots&\\ &&1 \end{matrix}}&&&\\ &\boxed{\begin{matrix} -1&&\\ &\ddots&\\ &&-1 \end{matrix}}&&\\ &&\boxed{\begin{matrix} \cos w&-\sin w\\ \sin w&\cos w \end{matrix}}&\\ &&&\boxed{\begin{matrix} \cos w&-\sin w\\ \sin w&\cos w \end{matrix}} \end{pmatrix}$
\end{document}

-