TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to get a plot like the one I sketched below, basically two blocks of the same matrix with arrows going up and anti-diagonally for the red block and arrows going up for the green one. The dots in the middle of the green one means to repeat the same pattern .... And I have as starting point the TikZ code below but I am not sure which would be the easiest way to do ... I struggle still to get conditions in the for loops of TikZ with the complicated markup.

enter image description here

As starting point I have this including a commented attempt to create the upper triangular effect omitting the arrows for elements below the diagonal but can't get this code to work.

    \clip (-0.3,-1.3) rectangle (8.3,4.3);
%   \foreach \x in {0,...,8} {
%       \foreach \y [evaluate=\y as \z using int(4-\y)] in {0,...,4} {
%           \pgfmathtruncatemacro{\myresult}{\x<\z ? 1 : 0}
%           \ifnum\myresult=0%
%           \node at (\x cm,\y cm) (g-\x-\y) {$a_{\x,\z}$};\fi
%       }
%   }
    \foreach \x in {0,...,8} {
      \foreach \y [evaluate=\y as \z using int(4-\y)] in {0,...,4} {
        \node at (\x cm,\y cm) (g-\x-\y) {$a_{\x,\z}$};
    % vertical dependency
    \foreach \x in {0,...,8} {
      \foreach \y in {0,...,3} {
        \draw[->,shorten <=2pt,shorten >=7pt] (g-\x-\y) -- +(0,20pt);
    % horizontal
    \foreach \x in {0,...,7} {
      \foreach \y in {0,...,4} {
        \draw[<-,shorten >=2pt,shorten >=7pt] (g-\x-\y) -- +(20pt,0);
    % diagonal
    \foreach \x in {1,...,8} {
      \foreach \y in {0,...,3} {
        \draw[->] (\x-.3,\y+.3) -- (\x - .6, \y+.6);

and the generated image in this case is (but actually I dont need the horizontal arrows):

enter image description here

share|improve this question
In part %horizontal comment the line which prints the horizontal arrows: ` % \draw[<-,shorten >=2pt,shorten >=7pt] (g-\x-\y) -- +(20pt,0);` – Kurt Sep 3 '12 at 21:23
up vote 37 down vote accepted

Maybe I took it a little too literal.




    \state{initial}[width=+\pgfdecoratedinputsegmentremainingdistance,auto corner on length=1mm,]{
        {% From
        {%  Control 1


[zeros/.style={},scale=0.8,transform shape,
xes/.style={outer sep=1.5pt,decoration=penciline,decorate}]
\foreach \y in {1,...,4}{
    \foreach \x in {1,...,5}{
    \node[zeros] (mynode-\x-\y) at (\y,-\x) {0};
    \node[xes,\pgfmathresult](mynode-\x-\y) at (\y,-\x) {X};
    \ifnum\x<\y\draw[<-,xes] (mynode-\x-\y) -- +(0,-0.7);\fi 
    \ifnum\x=\y\draw[<-,xes] (mynode-\x-\y) -- +(0,-0.7);\fi
    \ifnum\y<4\draw[<-,xes] (mynode-\x-\y) -- +(0.7,-0.7);\fi
\node[fit=(mynode-1-1)(mynode-5-4),draw,thick,xes,red,label=90:{\Large dependencies}] {};

    \foreach \x[remember=\x as \lastx] in {1,...,5}{
        \node (myvecs1-\x) at (0,-\x) {X};
        \node (myvecs2-\x) at (1,-\x) {X};
        \node (myvecsn-\x) at (5,-\x) {X};
        \draw[->,xes] (myvecs1-\x) -- (myvecs1-\lastx);
        \draw[->,xes] (myvecs2-\x) -- (myvecs2-\lastx);
        \draw[->,xes] (myvecsn-\x) -- (myvecsn-\lastx);
\node[fit=(myvecs1-1)(myvecsn-5),draw,thick,xes,green!50!blue,label=90:{\Large Free of diagonal dep.}] {};


enter image description here

Mostly stolen from

Simulating hand-drawn lines

TikZ marking several blocks in a matrix

and for the font

CTAN font catalogue

share|improve this answer
I'm speechless. It's amazing, my friend! :) – Paulo Cereda Sep 4 '12 at 0:59
The horizontal dots inside the green box are missing ;-) (I'm just kidding). – Gonzalo Medina Sep 4 '12 at 1:16
lol amazing! howcan I make it look not handwritten ?? lol – Giovanni Azua Sep 4 '12 at 3:47
@GiovanniAzua Just remove the decorations here and there and remove the font related commands for the base drawing. Note that the arrows are not from node-to-node so it might need some tweaks. Let me know if it doesn't solve your problem. – percusse Sep 4 '12 at 7:59

Your Answer


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.