(!包 pgf 错误:没有已知名为 m-2-2 的形状)

(!包 pgf 错误:没有已知名为 m-2-2 的形状)

在此处输入图片描述
我想从块 2 到块 7 画一条线,但出现此错误(!包 pgf 错误:没有已知的名为 m-2-2 的形状)

\tikzset{
desicion/.style={
    diamond,
    draw,
    text width=5em,
    text badly centered,
    inner sep=0pt
},
block/.style={
    rectangle,
    draw,
    text width=10em,
    text centered,
    rounded corners
},
cloud/.style={
    draw,
    ellipse,
    minimum height=2em
},
descr/.style={
    fill=white,
    inner sep=2.5pt
},
connector/.style={
    -latex,
    font=\scriptsize
},
rectangle connector/.style={
    connector,
    to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
    pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
    connector,
    to path=--(\tikztotarget) \tikztonodes
}
}



\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]
{
    |[block]| {Start}                       &  \\
    |[desicion]| {$d^{(i)}_{(n,m)} < 2r$?}  &  \\
    |[block]| {Estimate $I_{n,p}^{(i)} \rightarrow FBS_m$ }    & \\
    |[block]| {Estimate $\zeta^{(i*)}$ and $\varphi^{(i*)}_{n,p}$}    &   \\
    |[desicion]| {$o^{(i+1)}_{(n,m)} > o^{(i)}_{(n,m)}$?}  &  \\
    |[block]| {Apply}    &   \\
    |[block]| {End}    & \\
};
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\path [>=latex,->] (m-3-1) edge (m-4-1);
\path [>=latex,->] (m-4-1) edge (m-5-1);
\path [>=latex,->] (m-5-1) edge (m-6-1);
\path [>=latex,->] (m-6-1) edge (m-7-1);
\path [>=latex,->] (m-2-2) edge (m-7-2);

\end{tikzpicture}

答案1

您可以只使用一列来执行操作,如果不需要,则matrix不应使用:&

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix, arrows.meta, shapes}
\tikzset{
    desicion/.style={
        diamond,
        draw,
        text width=5em,
        text badly centered,
        inner sep=0pt
    },
    block/.style={
        rectangle,
        draw,
        text width=10em,
        text centered,
        rounded corners
    },
    cloud/.style={
        draw,
        ellipse,
        minimum height=2em
    },
    descr/.style={
        fill=white,
        inner sep=2.5pt
    },
    connector/.style={
        -latex,
        font=\scriptsize
    },
    rectangle connector/.style={
        connector,
        to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
        pos=0.5
    },
    rectangle connector/.default=-2cm,
    straight connector/.style={
        connector,
        to path=--(\tikztotarget) \tikztonodes
    }
}

\begin{document}
\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]
{
    |[block]| {Start}                         \\
    |[desicion]| {$d^{(i)}_{(n,m)} < 2r$?}    \\
    |[block]| {Estimate $I_{n,p}^{(i)} \rightarrow FBS_m$ }    \\
    |[block]| {Estimate $\zeta^{(i*)}$ and $\varphi^{(i*)}_{n,p}$}     \\
    |[desicion]| {$o^{(i+1)}_{(n,m)} > o^{(i)}_{(n,m)}$?}   \\
    |[block]| {Apply}      \\
    |[block]| {End}    \\
};
\path [-Latex] (m-1-1) edge (m-2-1);
\path [-Latex] (m-2-1) edge (m-3-1);
\path [-Latex] (m-3-1) edge (m-4-1);
\path [-Latex] (m-4-1) edge (m-5-1);
\path [-Latex] (m-5-1) edge (m-6-1);
\path [-Latex] (m-6-1) edge (m-7-1);
\draw [-Latex] (m-2-1.east) -- ++(2,0) |- (m-7-1.east);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

像这样?

在此处输入图片描述

但上图我用链中的节点来绘制(因为这种方式对我来说更简单,并且提供更简洁、清晰的代码):

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, chains, positioning, shapes}

\begin{document}
\tikzset{
desicion/.style={
    diamond,
    draw,
    text width=6em,
    aspect=1.2,
    align=flush center,
    inner sep=-0pt
},
block/.style={
    rectangle,
    draw,
    text width=10em,
    text centered,
    rounded corners
}
        }% end of tikzset

\begin{tikzpicture}[
           node distance = 5mm and 7mm,
             start chain = A going below,
every node/.append style = {on chain=A, join=by -Latex}
                    ]
\node[block]    {Start};
\node[desicion] {$d^{(i)}_{(n,m)} < 2r$?};
\node[block]    {Estimate $I_{n,p}^{(i)} \rightarrow FBS_m$};
\node[block]    {Estimate $\zeta^{(i*)}$ and $\varphi^{(i*)}_{n,p}$};
\node[desicion] {$o^{(i+1)}_{(n,m)} > o^{(i)}_{(n,m)}$?};
\node[block]    {Apply};
\node[block]    {End};
%
\draw[-Latex] (A-2.east) -- ++ (1,0) |- (A-7);
\end{tikzpicture}
\end{document}

相关内容