TransWikia.com

Package pgf Error: No shape named `chart -1-2' is known

TeX - LaTeX Asked by MaineRo on January 21, 2021

I am trying to make a flowchart in Latex, but I keep getting this error;
"Package pgf Error: No shape named `chart -1-2′ is known"

I looked up similar questions, but none use matrix.
Does anyone have an idea where my problem is?

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=ttfamilynormalsize}, 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}

enter image description here

2 Answers

Edit: Added are braces on the right side of flowchart.

Your flowchart can be simple drawn by use of chains library. At least code is much shorter, clear and less prone to errors. For example, in your MWE are beside errors in writing coordinates name and terminating of lines (corrected in the other answer) missed many arrows between nodes and fact, that the flowchart is much higher than page. That flowchart can be fit, in MWE below two measures have been taken: increase text area size and used wider nodes:

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}

enter image description here

Correct answer by Zarko on January 21, 2021

The problem lies in the spaces that you added in the node names. Please take care of these, because chart -1-2 is different from chart-1-2!

Also, each TikZ command should end with a semicolon.

Try this, but you still need to scale everything and check the connections between the nodes, I think:

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=ttfamilynormalsize}, 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}

Answered by Jasper Habicht on January 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP