4

I'm using tikz to make an array with arrows connecting different cells in order to explain how to get one cell using the others.

The problem is that the arrows are far to small to be visible.enter image description here

I also don't understand why the size of the arrows depends on the line.

I would really appreciate if anyone could explain me how to improve my code to make it look better.

Here's the code :

\begin{tikzpicture}

\draw[xstep=3cm,ystep=1.05cm,color=gray] (0,0) grid (18,6.3);
\matrix (magic) [matrix of nodes,
                inner sep=0pt,
                anchor=south west,
                nodes={inner sep=0pt,text width=3cm,align=center,minimum height=1cm}]
{
 & $\epsilon$ & A & B & C & D  \\
$\epsilon$ & 0 & 1 & 2 & 3 & 4 \\
D & 1 & 1 & 2 & 3 & 3 \\
A & 2 & 1 & 2 & 3 & 4 \\
B & 3 & 2 & 1 & 2 & 3 \\
C & 4 & 3 & 2 & 1 & 2 \\
};

\draw[thick,black,->] (magic-2-2) -- (magic-3-3);
\draw[thick,black,->] (magic-2-3) -- (magic-3-4);
\draw[thick,black,->] (magic-3-3) -- (magic-3-4);
\draw[thick,black,->] (magic-2-4) -- (magic-3-5);
\draw[thick,black,->] (magic-3-4) -- (magic-3-5);
\draw[thick,red,->] (magic-2-5) -- (magic-3-6);
\draw[thick,red,->] (magic-3-2) -- (magic-4-3);
\draw[thick,black,->] (magic-3-3) -- (magic-4-4);
\draw[thick,black,->] (magic-4-3) -- (magic-4-4);
\draw[thick,black,->] (magic-3-4) -- (magic-4-5);
\draw[thick,black,->] (magic-4-4) -- (magic-4-5);
\draw[thick,black,->] (magic-3-5) -- (magic-4-6);
\draw[thick,black,->] (magic-3-6) -- (magic-4-6);
\draw[thick,black,->] (magic-4-5) -- (magic-4-6);
\draw[thick,black,->] (magic-4-3) -- (magic-5-3);
\draw[thick,red,->] (magic-4-3) -- (magic-5-4);
\draw[thick,black,->] (magic-5-4) -- (magic-5-5);
\draw[thick,black,->] (magic-5-5) -- (magic-5-6);
\draw[thick,black,->] (magic-5-3) -- (magic-6-3);
\draw[thick,black,->] (magic-5-4) -- (magic-6-4);
\draw[thick,red,->] (magic-5-4) -- (magic-6-5);
\draw[thick,black,->] (magic-6-5) -- (magic-6-6);
\end{tikzpicture}

Please forgive me if my english isn't perfect or if the code isn't clear (I'm not english and I use latex for a short time).

Thanks a lot !

1
  • Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. This is especially important for tikz as there are numerous libraries. Commented Jun 15, 2016 at 15:11

1 Answer 1

3

See, if the following result is more close to what you like to have:

enter image description here

The code:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}

\draw[xstep=3cm,ystep=1.05cm,color=gray] (0,0) grid (18,6.3);
\matrix (magic) [matrix of nodes,
                inner sep=0pt,
                anchor=south west,
                nodes={inner sep=0pt,text width=3cm,align=center,minimum height=1cm}]
{
 & $\epsilon$ & A & B & C & D  \\
$\epsilon$ & 0 & 1 & 2 & 3 & 4 \\
D & 1 & 1 & 2 & 3 & 3 \\
A & 2 & 1 & 2 & 3 & 4 \\
B & 3 & 2 & 1 & 2 & 3 \\
C & 4 & 3 & 2 & 1 & 2 \\
};

\draw[thick,black,shorten <=7mm, shorten >=7mm,->] 
    (magic-2-2.center) edge (magic-3-3.center)
    (magic-2-3.center) edge (magic-3-4.center)
    (magic-3-3.center) edge (magic-3-4.center)
    (magic-2-4.center) edge (magic-3-5.center)
    (magic-3-4.center) edge (magic-3-5.center)
    (magic-3-3.center) edge (magic-4-4.center)
    (magic-4-3.center) edge (magic-4-4.center)
    (magic-3-4.center) edge (magic-4-5.center)
    (magic-4-4.center) edge (magic-4-5.center)
    (magic-3-5.center) edge (magic-4-6.center)
    (magic-4-5.center) edge (magic-4-6.center)
    (magic-5-4.center) edge (magic-5-5.center)
    (magic-5-5.center) edge (magic-5-6.center)
    (magic-6-5.center)  to  (magic-6-6.center)
    ;
\draw[thick,black,shorten <=3mm, shorten >=3mm,->]
    (magic-3-6.center) edge (magic-4-6.center)
    (magic-4-3.center) edge (magic-5-3.center)
    (magic-5-3.center) edge (magic-6-3.center)
    (magic-5-4.center)  to  (magic-6-4.center);

\draw[thick,red,shorten <=7mm, shorten >=7mm,->]
    (magic-2-5.center) edge (magic-3-6.center)
    (magic-3-2.center) edge (magic-4-3.center)
    (magic-4-3.center) edge (magic-5-4.center)
    (magic-5-4.center)  --  (magic-6-5.center);
\end{tikzpicture}
\end{document}

And, please in your future questions consider comment of Peter Grill!

2
  • This is exactly what I wanted. Thanks a lot !
    – Shinra
    Commented Jun 15, 2016 at 15:24
  • @Shinra, you are welcome! If you really like the answer, you can vote for it or even accept it! Happy TeX-ing!
    – Zarko
    Commented Jun 15, 2016 at 17:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .