程序包 pgf 错误:没有已知的名为“chart -1-2”的形状

程序包 pgf 错误:没有已知的名为“chart -1-2”的形状

我正在尝试在 Latex 中制作流程图,但一直收到此错误;“包 pgf 错误:没有已知的名为‘图表 -1-2’的形状”

我查过类似的问题,但都没用matrix。有人知道我的问题出在哪里吗?

\documentclass[a4paper, 12pt]{report}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix,calc,shapes}
%define styles for nodes
\tikzset{ treenode/.style = {shape=rectangle, rounded corners, draw, anchor=center, text width=5em, align=center, top color=white, bottom color=blue!20, inner sep=1ex}, decision/.style = {treenode, diamond, inner sep=0pt}, root/.style ={treenode, font=\Large, bottom color=red!30}, env/.style = {treenode, font=\ttfamily\normalsize}, finish/.style   = {root, bottom color=green!40}, dummy/.style    = {circle,draw}}
%create useful shortcuts
\newcommand{\yes}{edge node [above] {yes}}
\newcommand{\no}{edge  node [left]  {no}}

\begin{document}

\begin{tikzpicture}
\matrix (chart)
[
      matrix of nodes,
      column sep      = 3em,
      row sep         = 5ex,
      column 1/.style = {nodes={treenode}},
      column 2/.style = {nodes={treenode}}
    ]
{
       & |[root]| Collect data \\
       &  Preliminary checks on data quality  \\
       &  Diagnostics for relationships and strong interactions  \\
Remedial measures &     \\
       & | [decision]| Are remedial measures needed?  \\
       & Determine several potential useful subsets of explanatory variables; include known essential variables  \\
       & Investigate curvature and interaction effects more fully \\
Remedial measures & Study residuals and other diagnostics \\
      & | [decision]| Remedial measures needed?  \\
      & Select tentative model \\
      & | [ decision]| Validity checks?  \\
      & | [finish]| Final regression model  \\
};
\draw(chart -1-2) edge (chart -2-2)
\draw(chart -4-1.west) -- ++(-1,0) node[midway,above]{yes} |- (chart -3-2.west)
\draw(chart - 9 - 2.west) --++(-1,0) node[midway,above]{yes} |- (chart -7 -2.west)
\draw(chart -11 -2.west) --++(-2,0) node [midway,above] {no} |- (chart -1 -2.west)
\draw(chart -5 -2 ) \no (chart -6-2)
\draw(chart -9-2) \no (chart -10-2)
\draw(chart -11-2) \yes (chart -12- 2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

编辑:在流程图的右侧添加了括号。

您的流程图可以通过使用chains库来简单绘制。至少代码更短、更清晰,也更不容易出错。例如,在您的 MWE 中,除了编写坐标名称和行终止的错误(在另一个答案中已更正)之外,还遗漏了节点之间的许多箭头,而且流程图比页面高得多。该流程图可以适合,在 MWE 中采取了以下两项措施:增加文本区域大小并使用更宽的节点:

\documentclass[a4paper, 12pt]{report}
\usepackage[showframe,  % in real document remove this option
            margin=25mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                calc, chains,
                decorations.pathreplacing,%
                    calligraphy,% had to be after decorations.pathreplacing
                positioning,
                quotes,
                shadows, shapes.geometric}
\tikzset{
BC/.style = {
        decorate,
        decoration={calligraphic brace, amplitude=6pt,
        pre =moveto, pre  length=1pt,
        post=moveto, post length=1pt,
        raise=1mm},
        ultra thick,
        pen colour={#1}
        },
}

\begin{document}
  \centering
  \begin{tikzpicture}[
    node distance = 5mm and 8mm,
      start chain = A going below,
%
        arr/.style = {-Straight Barb, semithick},
      base/.style = {draw, rounded corners,
                     top color=white, bottom color=blue!20,
                     text width=68mm, minimum height=8mm,
                     align=center, drop shadow,
                     on chain=A},
     start/.style = {base, bottom color=red!20, text width=34mm},    
      stop/.style = {base, ellipse, text width=34mm,
                     bottom color=green!40},    
   process/.style = {base, fill=orange!30},                 
%        io/.style = {base, trapezium, trapezium stretches body,
%                     trapezium left angle=70, trapezium right angle=110,
%                     fill=blue!30},
  decision/.style = {base, bottom color=cyan!50, diamond, aspect=2, text width=34mm},
       lbl/.style = {label=above left:#1, font=\footnotesize}
                    ]
    \begin{scope}[nodes={join=by arr}]
\node [start]       {Collect data};             % <-- A-1
\node [process]     {Preliminary checks on data quality};
\node [process]     {Diagnostics for relationships and strong interactions Remedial measures};
\node [decision]    {Are remedial measures needed?};
\node [process]     {Determine several potential useful subsets
                     of explanatory variables; include known essential variables};
\node [process]     {Investigate curvature and interaction effects more fully  
                     Remedial measures};
\node [process]     {Study residuals and other diagnostics};
\node [decision]    {Remedial measures needed?};
\node [process]     {Select tentative model};
\node [decision]    {Validity checks?};
\node [stop]        {Final regression model};                     % <-- A-11   
    \end{scope}
% nodes in the left branch
\node [process, text width=32mm, 
       left=of $(A-3.west)!0.5!(A-3.west |- A-4)$] {Remedial measures needed?};
\node [process, text width=32mm, left=of A-7]      {Remedial measures};
% connection not considered in "join" macro
\coordinate[left=of A-12] (aux);
\draw[arr]  (A-10.west) node[lbl=No] {} -| (aux) |- (A-2);
\draw[arr]  (A-12) |- (A-3);
\draw[arr]  (A-4.west) node[lbl=Yes] {} -| (A-12);
%
\draw[arr]  (A-13) |- (A-6);
\draw[arr]  (A-8.west) node[lbl=Yes] {} -| (A-13);
% path edge quotes in main branch
\path   (A-4) to ["No"] (A-5.north)
        (A-8) to ["No"] (A-9.north)
        (A-10) to ["Yes"] (A-11.north);% braces
    \begin{scope}[nodes={text width=24mm, align=left, right=3mm}]
\coordinate (aux) at (A-1.north -| A-2.east);
\draw[BC=red]   (aux) -- 
                    node {some text in two rows} (A-4.south -| aux);
\draw[BC=red]   (aux |- A-5.north) -- 
                    node {some text longer test in three rows} (A-5.south -| aux);
\draw[BC=red]   (aux |- A-6.north) --
                    node {some text in two rows} (A-9.south -| aux);
\draw[BC=red]   (aux |- A-10.north) --
                    node {some text in two rows} (A-10.south -| aux);
    \end{scope}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

问题在于您在节点名称中添加的空格。请注意这些问题,因为chart -1-2不同于chart-1-2

此外,每个 TikZ 命令都应以分号结尾。

尝试一下这个,但是你仍然需要扩展所有内容并检查节点之间的连接,我认为:

\documentclass[a4paper, 12pt]{report}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix,calc,shapes}
%define styles for nodes
\tikzset{ treenode/.style = {shape=rectangle, rounded corners, draw, anchor=center, text width=5em, align=center, top color=white, bottom color=blue!20, inner sep=1ex}, decision/.style = {treenode, diamond, inner sep=0pt}, root/.style = {treenode, font=\Large, bottom color=red!30}, env/.style = {treenode, font=\ttfamily\normalsize}, finish/.style = {root, bottom color=green!40}, dummy/.style = {circle,draw}}
%create useful shortcuts
\newcommand{\yes}{edge node [above] {yes}}
\newcommand{\no}{edge node [left] {no}}

\begin{document}

\begin{tikzpicture}
\matrix (chart)
[
      matrix of nodes,
      column sep      = 3em,
      row sep         = 5ex,
      column 1/.style = {nodes={treenode}},
      column 2/.style = {nodes={treenode}}
    ]
{
       & |[root]| Collect data \\
       &  Preliminary checks on data quality  \\
       &  Diagnostics for relationships and strong interactions  \\
Remedial measures &     \\
       & |[decision]| Are remedial measures needed?  \\
       & Determine several potential useful subsets of explanatory variables; include known essential variables  \\
       & Investigate curvature and interaction effects more fully \\
Remedial measures & Study residuals and other diagnostics \\
      & |[decision]| Remedial measures needed?  \\
      & Select tentative model \\
      & |[decision]| Validity checks?  \\
      & |[finish]| Final regression model  \\
};
\draw(chart-1-2) edge (chart-2-2);
\draw(chart-4-1.west) -- ++(-1,0) node[midway,above]{yes} |- (chart-3-2.west);
\draw(chart-9-2.west) --++(-1,0) node[midway,above]{yes} |- (chart-7-2.west);
\draw(chart-11-2.west) --++(-2,0) node [midway,above] {no} |- (chart-1-2.west);
\draw(chart-5-2) \no (chart-6-2);
\draw(chart-9-2) \no (chart-10-2);
\draw(chart-11-2) \yes (chart-12-2);
\end{tikzpicture}
\end{document}

相关内容