后动作中装饰中的第二个标记坐标无法识别

后动作中装饰中的第二个标记坐标无法识别

在装饰中,第二个标记坐标无法识别:

  \draw[thick,red,zigzag,postaction={
    decoration={
        markings,
        mark=at position 0.7 with \coordinate (x);
        mark=at position 0.5 with \coordinate (z); %unable to recognize z
    },
    decorate
  }] (-2,0) coordinate(a) -- (2,0) coordinate(b);

MWE如下:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\tikzset{zigzag/.style={decorate,decoration=zigzag}}
\begin{document}
\begin{tikzpicture}
  \coordinate (c) at (0,-2);
  \coordinate (d) at (4,-2);
  \coordinate (e) at (2,-4);
  \draw[thick,red,zigzag,postaction={
    decoration={
        markings,
        mark=at position 0.7 with \coordinate (x);
        mark=at position 0.5 with \coordinate (z); %unable to recognize z
    },
    decorate
  }] (-2,0) coordinate(a) -- (2,0) coordinate(b);

  \draw[thick,fill=blue!20] (c) -- (b) -- (d) -- (e) -- cycle;
  \draw[thick,postaction={
    decoration={
        markings,
        mark = at position 0.7 with \coordinate (y);
    },
    decorate
  }] (a) -- (c);
  \draw[thick,red,dashed] (x) -- (y);

  \node[above = 10ex of z,red] (sn) {singularity};
\end{tikzpicture}
\end{document} 

当我使用 PDFLaTeX 编译此代码时,得到以下结果:

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

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

l.32   \node[above = 10ex of z,red]
                                    (sn) {singularity};
? 

请指导我哪里做错了。

答案1

您必须用逗号分隔选项。将复杂的参数放在括号中也是一个好主意。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\tikzset{zigzag/.style={decorate,decoration=zigzag}}
\begin{document}
\begin{tikzpicture}
  \coordinate (c) at (0,-2);
  \coordinate (d) at (4,-2);
  \coordinate (e) at (2,-4);
  \draw[thick,red,zigzag,postaction={
    decoration={
        markings,
        mark=at position 0.7 with {\coordinate (x);},
        mark=at position 0.5 with {\coordinate (z);},
    },
    decorate
  }] (-2,0) coordinate(a) -- (2,0) coordinate(b);

  \draw[thick,fill=blue!20] (c) -- (b) -- (d) -- (e) -- cycle;
  \draw[thick,postaction={
    decoration={
        markings,
        mark = at position 0.7 with \coordinate (y);
    },
    decorate
  }] (a) -- (c);
  \draw[thick,red,dashed] (x) -- (y);

  \node[above = 10ex of z,red] (sn) {singularity};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容