Tikz,没有已知错误的形状

Tikz,没有已知错误的形状

我正在尝试按照 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}

得到如下图纸。在此处输入图片描述

运行 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''' )
                                                  ;
?

我尝试将其放在\coordinate ([transform canvas={shift={(-36:-.5)}}]G) at (B2) ;不同的地方,但错误仍然相同。任何帮助都非常感谢。

答案1

您在 MWE 中遇到的问题已通过上述评论得到解决。让我再次指出,您的 MWE 非常复杂,很难在其中找到任何错误。我不知道您决定以这种方式绘制图片背后的原因是什么。我将以不同的方式绘制它:

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

与您的代码相比,主要区别是:

  • 所有使用的坐标均在图片代码的开头收集,并借助“\foreach 循环”进行定义。坐标还包含其标签。
  • 节点标签的位置是经过精心设计的:位置考虑相对于圆的坐标角度,该圆环绕五边形,原点
  • 画布变换仅使用两次:在移动测量时ab
  • 所有图片都在一个层上
  • 代码(就我看来)有很好的注释,所以应该很容易在一年后找到图像中的任何元素(当你已经忘记了你在绘画时想到了什么……)。

在此处输入图片描述

据我所知,所需图像与上述 MWE 获得的图像之间的差异很小(标签定位、大小)。 可以使用和的新值轻松更改大小routrin将坐标标签定位在内五边形之外需要将阴影区域放入背景层。 在这种情况下,您需要添加 TikZ 库backgrounds并在上述 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;

编辑: 看起来图片上的两个五边形应该在非绘图侧互相接触。因此我相应地更改了内圆的计算(请参阅代码以了解具体方法)。

为了证明计算是正确的,你可以在图片末尾添加:

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

相关内容