箭头大小的问题(在 tikz 矩阵中)

箭头大小的问题(在 tikz 矩阵中)

我正在使用 tikz 制作一个带有连接不同单元格的箭头的数组,以解释如何使用其他单元格来获取一个单元格。

问题是箭头太小而无法看见。在此处输入图片描述

我也不明白为什么箭头的大小取决于线。

如果有人能向我解释如何改进我的代码以使其看起来更好,我将不胜感激。

代码如下:

\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}

如果我的英语不够完美或者代码不够清晰,请原谅我(我不是英国人并且我只使用过乳胶一小段时间)。

多谢 !

答案1

看看以下结果是否更接近您想要的结果:

在此处输入图片描述

代码:

\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}

并且,请在您以后的问题中考虑 Peter Grill 的评论!

相关内容