I am trying to compile following MWE

\documentclass[border=9 pt]{standalone}
\pgfplotsset{grid style={dashed,gray}}

  /tikz/on layer/.code={
  /tikz/node on layer/.code={
  /tikz/end node on layer/.code={




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


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.

  • 1
    of topic: your code is very complicated and not well structured, so it is difficult to digging in it and search where error is occur, regardless that error message is very clear: you didn't define node or coordinate G. – Zarko Jul 1 '16 at 19:34
  • 3
    Also your \coordinate ([transform canvas={shift={(-36:-.5)}}]G) at (B2) ; doesn't define coordinate G. Correct syntax is \coordinate[<options>] (<coordinate name>) at (<coordinete>); . It seems that in your definition you lost left parenthesis ... \coordinate ([transform canvas={shift={(-36:-.5)}}] (G) at (B2) ; – Zarko Jul 1 '16 at 19:40
  • thanks @Zarko . \coordinate (G) at ($([{shift={(-36:-.5)}}] B2)$); did the trick. – praveen pathak Jul 3 '16 at 4:46

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:


               > = latex,
every label/.style = {label distance=0mm, inner sep=1mm, font=\small}
% 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]
\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);

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)$);


% 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);
  • @praveen pathak, I redrew your image. See, if suggested code is useful to you. – Zarko Jul 3 '16 at 11:21
  • I had to draw many such polygon figures, starting from triangle to dodecagon. Very first code I wrote was for hexagon and then to generate other polygons I did minimal changes in forloop and coordinate shift in hexagon code. Hence it is a weird code which perhaps only I was comfortable with. But to put in this forum I should have cleaned it. My apologies. However your code is minimal and can be used to draw other polygons also. Thanks. – praveen pathak Jul 6 '16 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.