Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\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 enter image description here

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

share|improve this question
    
Welcome to TeX.SX! You may want to have a look to Array cell highlighting tikz although the matrix is not directly typeset with TikZ. Other methods are illustrated in Highlight elements in the matrix. To have U^k in the middle, have a look to use of tikzpicture matrix in align or gather environment. –  Claudio Fiandrino Aug 27 at 10:55

2 Answers 2

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}

enter image description here

share|improve this answer
    
\begin{tikzpicture}[baseline] because m.center is already the baseline reference. –  Ignasi Aug 27 at 12:21
    
@Ignasi I wanted to be explicit ;-). You are right. :-) –  Harish Kumar Aug 27 at 12:22
    
@Ignasi not if you have bottom delimiters or other items inside the picture. –  percusse Aug 27 at 13:05
    
This one worked very well for me, thank you very much. –  mfg Aug 27 at 15:13
    
@percusse My fault. I just tested with the matrix. –  Ignasi Aug 27 at 17:16

I've discovered easy bundle in CTAN and this is a good question to test easybmat package.

As usual you need to know columns number but also rows number. It's possible to select different alignemt (l,c,r) for rows and columns. And it's possible to draw paths between elements.

\documentclass{article}
\usepackage{amsmath}
\usepackage{easybmat}

\begin{document}
\begin{equation*}
    U^{k} = \left(\begin{BMAT}{cccccccc}{ccccccccc}
                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 &  & &   &   
    \addpath{(1,0,0)rrruuulllddd}
    \addpath{(3,3,0)rrrrruuuuulllllddddd}
    \end{BMAT}\right)
\end{equation*}
\end{document}

enter image description here

share|improve this answer
    
This one is also very good, especially that the rectangles don't overlap, merely that the empty space at the top of the big rectangle is a bit out of order –  mfg Aug 27 at 15:16
    
@mfg And also the right space on the small one. May be it's possible to adjust it but this was my just first test with easybmat and used default parameters. –  Ignasi Aug 27 at 17:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.