[Tex/LaTex] Tikz, no shape named is known error

coordinatestikz-pgftikz-shape

I am trying to compile following MWE

\documentclass[border=9 pt]{standalone}
\usepackage{epsfig,graphicx,tikz}
\usepackage{standalone}
\usetikzlibrary{intersections}
\usepackage{pgfplots}
\usepackage{comment}
\tikzset{>=latex}
\usetikzlibrary{calc,scopes}
\pgfdeclarelayer{back}
\pgfdeclarelayer{front}
\pgfsetlayers{back,main,front}
\pgfplotsset{grid style={dashed,gray}}

\makeatletter
\pgfkeys{%
  /tikz/on layer/.code={
    \pgfonlayer{#1}\begingroup
    \aftergroup\endpgfonlayer
    \aftergroup\endgroup
  },
  /tikz/node on layer/.code={
    \gdef\node@@on@layer{%
      \setbox\tikz@tempbox=\hbox\bgroup\pgfonlayer{#1}\unhbox\tikz@tempbox\endpgfonlayer\egroup}
    \aftergroup\node@on@layer
  },
  /tikz/end node on layer/.code={
    \endpgfonlayer\endgroup\endgroup
  }
}

\def\node@on@layer{\aftergroup\node@@on@layer}

\makeatother
%\usepackage{pgfmath}
\usepackage{pgf,tikz,subfigure}
\usepackage{tkz-graph}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes,positioning}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}[scale=3]
%\begin{scope}
\def\a{1}
\def\n{5}
\def\b{.65}
\filldraw [fill=gray!30] (0,0)
\foreach \i in {1,2,...,5}
{-- ++(72*\i:\a) coordinate (A\i)
};

\draw [dotted,on layer=front] (A2)--($(A4)!0.5!(A5)$);
\draw [dotted,on layer=front] (A4)--++(54:1.7) node[above,right] {$K$} coordinate (K);
\draw [on layer=front,->] (K) --++ (54:2mm) node [above] {$x$};
\filldraw[black,on layer=front](K) circle (.45pt);
\node[on layer=front,above,xshift=1mm] at (A1)  {$J$};
\node[on layer=front,above] at (A2)  {$D$};
\node[on layer=front,left] at (A3)  {$C$};
\node[on layer=front, left] at (A4)  {$B$};
\node [on layer=front,right] at (A5)  {$A$};

%\node[on layer=front,right] at (A1)  {$G'$};
%\draw[->,on layer=front] (A1)--++(18:2mm) node [right] {$x$};
\filldraw[rotate=-36,fill=white,on layer=main,transform canvas={shift=(-36:-.5)}] (A1)
\foreach \i in {1,2,...,5}
{-- ++(-72*\i:\b) coordinate [every coordinate/.style={shift={(-36:-.5)}}] (B\i)
};

\draw [line width=2mm,on layer=main,white,transform canvas={shift=(-36:-.5)}] (B4)--(B5);

\coordinate ([transform canvas={shift={(-36:-.5)}}]G) at (B2) ; % Error is here

\filldraw[black,transform canvas={shift={(-36:-.5)}}](B2) circle (.45pt) node [left] {$G$};

\coordinate [transform canvas={shift={(-36:-.5)}}](G'') at   ($(B3)!0.5!(B4)$);

\coordinate (G''') at  at ($(A2)!0.5!(A3)$);

\coordinate (O) at (intersection of A1--G and A5--G''' );

\draw [on layer=front,dashed] (O) circle ({(\a)/(2*sin(180/\n))});
\filldraw[black,on layer=front](O) circle (.45pt) node [right] {$O$};

\draw [<->,dashed,transform canvas={yshift=-1.5mm}] (A5)--(A4) node [yshift=-1.5mm,midway] {$a$};

%\draw [on layer=front,dashed] (B4)--(B5)--(B1);
\draw [dotted,transform canvas={shift=(-36:-.5)},on layer=front] (B4)--($(B1)!0.5!(B2)$);
%\node[on layer=front,right] at (B1)  {$A$};
%\draw [<->,dashed,transform canvas={yshift=-1.5mm}] (B1)--(B2) node [yshift=-1.5mm,midway] {$b$};
\draw [<->,dashed,transform canvas={shift={(-36:-.5)}},right,transform canvas={yshift={(-4mm)}}] (B1)--(B2) node [yshift=-2mm,midway] {$b$};

\node[on layer=front,left,transform canvas={shift={(-36:-.5)}}] at (B3)  {$F$};
\node[on layer=front,transform canvas={shift={(-36:-.5)}},right] at (B1)  {$H$};
\node[on layer=front,transform canvas={shift={(-36:-.5)}},left] at (B5)  {$I$};

\coordinate [transform canvas={shift=(-36:-.5)}] (O') at (intersection of B5--G and B1--G'');

\draw [on layer=front,dashed,transform canvas={shift={(-36:-.5)}}] (O') circle ({(\b)/(2*sin(180/\n))});
\filldraw[black,on layer=front,transform canvas={shift=(-36:-.5)}](O') circle (.45pt) node [right] {$O'$};
\node[on layer=front,below,transform canvas={shift={(-36:-.5)}}] at (B4)  {$E$};
\end{tikzpicture}

\end{document}

to get following drawing. enter image description here

I am getting following error after running pdflatex

! Package pgf Error: No shape named G is known.

See the pgf package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.78 ...) at (intersection of A1--G and A5--G''' )
                                                  ;
?

I tried to put \coordinate ([transform canvas={shift={(-36:-.5)}}]G) at (B2) ; at different places but still error is same. Any help is appreciated.

Best Answer

The problem, which you faced in your MWE was solved by help of above comments. Let me pointed again, your MWE is very complex and in it is difficult find any error. I don't know what is is behind of your decisions to draw your picture on such a way. I will draw it on a different way:

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

\begin{document}
    \begin{tikzpicture}[%scale=?,
               > = latex,
every label/.style = {label distance=0mm, inner sep=1mm, font=\small}
                        ]
\def\rout{32}
\def\rin{24}
% coordinate of point K
\coordinate[label=right:K]  (K) at (90-360/10:\rout mm);
% coordinates of circles origin
\coordinate[label=right:O]  (O)  at (0,0);
    % that both pentagons can tach each other  in direction 
    % of K coordinate, i.e. in (90 - 360/10) degrees
    % the offset of inner box origin had to be moved for distance
    % (\rouot - \rin)*cos(36) [geometry properties]
    \pgfmathparse{(\rout-\rin)*cos(36)}
\coordinate[label=right:O'] (O') at (90-360/10:\pgfmathresult mm); 
\coordinate[label=right:O'] (O') at ($(O)!{6/32}!(K)$); 
% coordinates of pentagon encircled with outer circle
\foreach \i [count=\ix from 0] in {D, C, B, A, J}
    \coordinate[label={[anchor={\ix*360/5-90}]{90+\ix*360/5}:\i}] (c1\ix) at ({90+\ix*360/5}:\rout mm);
% coordinates of pentagon encircled with inner circle
\foreach \i [count=\ix from 0] in {E, F, G, H, I}
    \coordinate[label={[anchor={\ix*360/5+90}]{90+\ix*360/5}:\i}] (c2\ix) at ($(O')+(90+\ix*360/5:\rin mm)$);
% shaded field
\draw[thick,fill=gray!30]   (c10) -- (c11) -- (c12) -- (c13) -- (c14) --
                            (c24) -- (c23) -- (c22) -- (c21) -- (c20) -- cycle;
% circles
\draw[dashed] (O)   circle (\rout mm);  % outer circle
\draw[dashed] (O')  circle (\rin  mm);  % inner circle
% dots at G, O, O', and K
\fill[black]    (c22) circle (0.5mm) (O) circle (0.5mm) (O') circle (0.5mm)   (K) circle (0.5mm);
% line B -- K
\draw[densely dotted]   (c12) -- (K);
% arrow x
\draw[->,thick]         (K) -- + (90-360/10:7mm) node[above] {$x$};
% vertical dotted lines
\draw[densely dotted,thick]   
    (c10) -- (c10 |- c12)
    (c20) -- (c20 |- c22);
% measures a and b
\draw[dashed,<->,thick,transform canvas={yshift=-5mm}] 
    (c22) -- node[below] {$b$} (c23);
\draw[dashed,<->,thick,transform canvas={yshift=-2mm}]
    (c12) -- node[below] {$a$} (c13);
\end{tikzpicture}
\end{document}

Main differences in comparison to your code are:

  • all used coordinates are collected on begin of picture'd code and defined by help of `\foreach loops. Coordinates also contain their labels.
  • node labels are deliberately positioned: position consider the angle of coordinate in respect to circle, which encircle pentagon, origin
  • canvas transform is used only twice: at moving measures a and b
  • all picture is on one layer
  • codes is well (at I thing so) documented with comments, so it should be easy find any element in image after year (when you already forgot, what you have in mind at drawing ...).

enter image description here

As far as I see, the difference between desired and by above MWE obtained image is minimal (positioning of labels, size). The size can be easily changed with new values for rout and rin, positioning of coordinates labels outside of inner pentagon require to pot shaded area an background layer. In this case you need to add TikZ library backgrounds and make the following changes in the above MWE:

% coordinates of pentagon encircled with inner circle
\foreach \i [count=\ix from 0] in {E, F, G, H, I}
    \coordinate[label={[anchor={\ix*360/5-90}]{90+\ix*360/5}:\i}] (c2\ix) at ($(O')+(90+\ix*360/5:\rin mm)$);

and:

% shaded field
\scoped[on background layer]% <-- new
\draw[thick,fill=gray!30]   (c10) -- (c11) -- (c12) -- (c13) -- (c14) --
                            (c24) -- (c23) -- (c22) -- (c21) -- (c20) -- cycle;

Edit: It seems that both pentagons on picture should touch each other on non drawing side. Therefore I change calculation of inner circle accordingle (see code for description how).

For proof, that the calculation is correct, you can add on the end of picture:

\draw[very thick,semitransparent,red] (c10) -- (c14);