# Partitioned matrix in tikz

I got the following partitioned matrix

through this tikz code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning}

\begin{document}

% Matrix U with its Column and Row variances
\begin{center}

\begin{tikzpicture}
\matrix [matrix of math nodes] (eqU) {
\mathbf{U}= \\
};

\matrix [right=2pt of eqU, matrix of math nodes,left delimiter=[,right delimiter={]},row sep=0.2cm,column sep=0.2cm] (U) {
u_{1}^{\left(1\right)} & \ldots & u_{1}^{\left(j\right)} & \ldots & u_{1}^{\left(t\right)}\\
\vdots & \ddots & \vdots & \ddots & \vdots\\
u_{k}^{\left(1\right)} & \ldots & u_{k}^{\left(j\right)} & \ldots & u_{k}^{\left(t\right)}\\
\vdots & \ddots & \vdots & \ddots & \vdots\\
u_{r}^{\left(1\right)} & \ldots & u_{r}^{\left(j\right)} & \ldots & u_{r}^{\left(t\right)} \\
};

\draw[color=red] (U-1-1.north west) -- (U-1-1.north east) -- (U-5-1.south east) -- (U-5-1.south west)-- (U-1-1.north west);
\draw[color=red] (U-1-3.north west) -- (U-1-3.north east) -- (U-5-3.south east) -- (U-5-3.south west)-- (U-1-3.north west);
\draw[color=red] (U-1-5.north west) -- (U-1-5.north east) -- (U-5-5.south east) -- (U-5-5.south west)-- (U-1-5.north west);

\draw[color=blue, dashed] (U-1-1.north west) -- (U-1-5.north east) -- (U-1-5.south east) -- (U-1-5.south west)-- (U-1-1.south west);
\draw[color=blue, dashed] (U-3-1.north west) -- (U-3-5.north east) -- (U-3-5.south east) -- (U-3-5.south west)-- (U-3-1.south west);
\draw[color=blue, dashed] (U-5-1.north west) -- (U-5-5.north east) -- (U-5-5.south east) -- (U-5-5.south west)-- (U-5-1.south west);

\node[below=5pt  of U-5-1, red] (below-1) {$\mathbf{G}^{\left(1, 1\right)}$};
\node[below=12pt of U-5-2, red] (below-2) {\ldots};
\node[below=5pt  of U-5-3, red] (below-3) {$\mathbf{G}^{\left(j, j\right)}$};
\node[below=12pt of U-5-4, red] (below-4) {\ldots};
\node[below=5pt  of U-5-5, red] (below-5) {$\mathbf{G}^{\left(t, t\right)}$};

\draw[<->, thick, red, bend right=60]       (U-5-1.south) to  node[below, pos=0.5,sloped]   {$\mathbf{G}^{\left(1, j\right)}$} (U-5-3.south);
\draw[<->, thick, red, bend right=60]       (U-5-3.south) to  node[below, pos=0.5,sloped]   {$\mathbf{G}^{\left(j, t\right)}$} (U-5-5.south);

\node[right=7pt  of U-1-5, blue] (right-1) {$\mathbf{H}_{11}$};
\node[right=17pt of U-2-5, blue] (right-2) {\vdots};
\node[right=7pt  of U-3-5, blue] (right-3) {$\mathbf{H}_{kk}$};
\node[right=17pt of U-4-5, blue] (right-4) {\vdots};
\node[right=7pt  of U-5-5, blue] (right-5) {$\mathbf{H}_{qq}$};

\draw[<->, thick, blue, bend left=60]       (U-1-5) to  node[above, pos=0.5]    {$\mathbf{H}_{1k}$} (U-3-5);
\draw[<->, thick, blue, bend left=60]       (U-3-5) to  node[above, pos=0.5]    {$\mathbf{H}_{jk}$} (U-5-5);

\end{tikzpicture}

\end{center}

\end{document}


I have some issues (described in following questions) with this output.

Issues/Questions

1. Arrows joining columns are overlapping and also I want to extract them out too and the same for the arrows joining rows.
2. Nodes for arrows joining the rows are not well aligned.
3. How the shades for arrows can be extending further to differentiate from column shadings?

I'd highly appreciate your help and time to figure out these issues and look forward to any recommendation and suggestions to improve this partitioned matrix. Thanks

I think you can do more simplifications both code-wise and presentation-wise. Once you start making it visual, in my opinion, you have to go all the way. In other words, they should have strong meaning, even though they don't have strong visual cues. Here as you complain, things are garbled and your row and column rectangles seem like a mistake due to the overlap since they don't have enough strong meaning. Also you don't need to use \ldots,\vdots since you are already using TikZ! I don't know what the G and H maps do but you shouldn't try to squeeze them in an extra row since you have already decided to color up the whole matrix. You shouldn't stop until it makes sense. So my suggestion is (possibly with the need of further tweaking) :

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\begin{document}

What if the rest of the world was hopelessly drowning in vain? Where would our
self pity run? Suddenly everyone cares and we perform some row/column operations as the
following:
$\mathbf{U} = \begin{tikzpicture}[baseline=(U.center)] \matrix [matrix of math nodes,left delimiter=[,right delimiter={]},nodes={outer sep=1pt}] (U) { u_{1}^{\left(1\right)} &[1cm] u_{1}^{\left(j\right)} &[1cm] u_{1}^{\left(t\right)} \\[1cm] u_{k}^{\left(1\right)} & u_{k}^{\left(j\right)} & u_{k}^{\left(t\right)} \\[1cm] u_{r}^{\left(1\right)} & u_{r}^{\left(j\right)} & u_{r}^{\left(t\right)} \\ }; \foreach \x/\y/\z in {1/1/1,2/k/j,3/q/t}{ \draw[red] ([shift={(1pt,2pt)}]U-1-\x.north west) rectangle ([shift={(-1pt,-2pt)}]U-3-\x.south east); \draw[blue,dashed] ([shift={(-2pt,-1pt)}]U-\x-1.north west) rectangle ([shift={(2pt,1pt)}]U-\x-3.south east); \draw[thick,loosely dotted] (U-\x-1) -- (U-\x-2) -- (U-\x-3); \draw[thick,loosely dotted] (U-1-\x) -- (U-2-\x) -- (U-3-\x); \node[blue,right = 3 mm of U-\x-3] (U-\x-4) {\mathbf{H}_{\y\y}}; \node[red,below= 1 mm of U-3-\x] (U-4-\x) {\mathbf{G}^{(\z,\z)}}; }; \draw[thick,loosely dotted] (U-1-1) -- (U-2-2) -- (U-3-3) (U-1-2) -- (U-2-3) (U-2-1) -- (U-3-2); \draw[thick,loosely dotted,red] (U-4-1) -- (U-4-2) -- (U-4-3); \draw[thick,loosely dotted,blue] (U-1-4) -- (U-2-4) -- (U-3-4); \draw[<->, thick, red, bend right=45] (U-4-1) to node[below, pos=0.5,sloped] {\mathbf{G}^{\left(1, j\right)}} (U-4-2); \draw[<->, thick, red, bend right=45] (U-4-2) to node[below, pos=0.5,sloped] {\mathbf{G}^{\left(j, t\right)}} (U-4-3); \draw[<->, thick, blue, bend left=60] (U-1-4) to node[right, pos=0.5] {\mathbf{H}_{1k}} (U-2-4); \draw[<->, thick, blue, bend left=60] (U-2-4) to node[right, pos=0.5] {\mathbf{H}_{jk}} (U-3-4); \end{tikzpicture}$
where we used colorful lines in the sand. People in prayer for me,everyone there for me. Sometimes I feel
I should face this alone. My soul exposed. It calms me to know that I won't.
\end{document}


Is it me or bottom G maps make smiley faces?

• Awesome answer. Thanks a lot for your help. Your answer address my all issues. I'd prefer three dots instead of six and one more thing that $\mathbf{G}^{\left(1, j\right)}$ is for first and j-th column not for $\mathbf{G}^{\left(1, 1\right)}$ and $\mathbf{G}^{\left(k, k\right)}$. I'd appreciate if you give feedback on these two things. Thanks – MYaseen208 Apr 28 '12 at 21:39
• @MYaseen208 Well, actually there are no 6 dots but rather dotted TikZ lines :) So I don't decide on how many dots appear but you can define your dashed line style with puttinh \tikzstyle{more loosely dotted}=[dash pattern=on \pgflinewidth off 7.5pt] in your preamble and changing the related \draw command options. – percusse Apr 28 '12 at 21:58
• @MYaseen208 Regarding the other one, I guess you mean something like a middle coordinate somewhere. You can try the following \draw[<->, thick, red, bend right=60] (U-4-1.-45) to node[below, pos=0.5,sloped] {$\mathbf{G}^{\left(1, j\right)}$} ($(U-4-1.-45)!0.5!(U-4-2.-135)$); as a starting point and modify further (with calc library). – percusse Apr 28 '12 at 21:59