# [Tex/LaTex] using tikz for rectangle in matrix

tikz-pgf

\begin{equation*}
U^{k} = \begin{tikzpicture}
\matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m)
{
z^{k}     &  0 & \cdots & s z^{0} & s z^{1} & \cdots & s z^{k-2} & s    z^{k-1} \\
z^{k-1} s &  \vdots&    & -\overline{z} & s^{2} z^{0}   & \cdots & s^{2} z^{k-3} & s^{2} z^{k-2} \\
z^{k-2} s &   & &  & -\overline{z} & s^{2} z^{0} & \cdots & s^{2} z^{k-3} \\
\vdots    &   & &  &   & \ddots & \ddots & \vdots \\
z s       & \vdots&  &   & 0 &   & -\overline{z} & s^{2} z^{0} \\
s         & 0 & \cdots &  &   &   &   & -\overline{z} \\
0         & 1 &   & 0 &  &  &   &   \\
\vdots    &   & \ddots & &  &   & 0 &   \\
0         & 0 &   & 1 &  & &   &   \\
};
\draw (m-2-4.north west) rectangle (m-6-8.south east);
\draw (m-7-2.north west) rectangle (m-9-4.south east);
\end{tikzpicture}
\end{equation*}


thats my code and the result

the one rectangle is to small. any ideas?
and to have the "U^k=" in the middle?

To bring U^k= to the middle use [baseline={(m.center)}] as the option to the \begin{tikzpicture}. and to make the rectangle bigger use (m-6-8.south east-|m-2-8.north east) in

 \draw (m-2-4.north west) rectangle (m-6-8.south east-|m-2-8.north east);


which means x coordinate same as m-2-8.north east and y coordinate same as that of m-6-8.south east.

Code:

\documentclass{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{matrix}
\begin{document}
\begin{equation*}
U^{k} = \begin{tikzpicture}[baseline={(m.center)}]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m)
{
z^{k}     &  0 & \cdots & s z^{0} & s z^{1} & \cdots & s z^{k-2} & s    z^{k-1} \\
z^{k-1} s &  \vdots&    & -\overline{z} & s^{2} z^{0}   & \cdots & s^{2} z^{k-3} & s^{2} z^{k-2} \\
z^{k-2} s &   & &  & -\overline{z} & s^{2} z^{0} & \cdots & s^{2} z^{k-3} \\
\vdots    &   & &  &   & \ddots & \ddots & \vdots \\
z s       & \vdots&  &   & 0 &   & -\overline{z} & s^{2} z^{0} \\
s         & 0 & \cdots &  &   &   &   & -\overline{z} \\
0         & 1 &   & 0 &  &  &   &   \\
\vdots    &   & \ddots & &  &   & 0 &   \\
0         & 0 &   & 1 &  & &   &   \\
};
\draw (m-2-4.north west) rectangle (m-6-8.south east-|m-2-8.north east);
\draw (m-7-2.north west) rectangle (m-9-4.south east);
\end{tikzpicture}
\end{equation*}
\end{document}