TikZ 绘制失败

TikZ 绘制失败

我正在尝试使用 TikZ 绘制下图,我确信命令是正确的,但是我收到以下错误:

“!包 pgfkeys 错误:我不知道密钥‘/tikz/closed’,我将忽略它。也许你拼错了。”

有人能帮我解决这个问题吗?

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,shapes.geometric}
\colorlet{myred}{red!60!black}
\colorlet{mygreen}{green!40!black}
\usetikzlibrary{shapes,arrows}
\usepackage{pgfplots}
\usepgfplotslibrary{units}


\begin{document}

\begin{tikzpicture}
\draw[thick,->] (52,0) -- (60,0) node[anchor=north west] {$x'$};
\draw[thick,->] (56,-03) -- (56,03) node[anchor=south east] {$x_N$};
\node[draw=red,dashed,thick,semicircle,minimum width=4cm] (n) at (56,0.8) {};
\node[draw=blue, dashed,thick,semicircle,minimum width=2cm] (n2) at (56,0.4) {};
\node[draw=green,circle,minimum width=4cm] (n3) at (56,0) {};


\draw (56,0) node[below right] {$O$} node{$\bullet$};
\draw (58,0) node[below right] {\color{red} $1$} node{};
\draw (54,0) node[below left] {\color{red} -$1$} node{};
\draw (56.8,0) node[below right] {\color{blue} $r$} node{};
\draw (55.3,0) node[below left] {\color{blue} -$r$} node{};


\draw[red, ->] (n.400) -- +(0.7,0.3) node[pos=1.7]{\color{red} $I^{+}(1)$};
\draw[green, ->] (n3.300) -- +(0.7,-0.3) node[pos=1.5]{\color{green}$I(1)$};
\draw[red, ->] (n.210) -- +(-0.7,-2.3) node[pos=1.2]{\color{red}$\Gamma_1$};
\draw[blue, ->] (n2.320) -- +(0.2,-0.5) node[pos=1.5]{\color{blue}$\Gamma_{r}$};



\node[draw,circle,minimum width=2cm] (n1) at (50,3) {};
\begin{scope}
\clip[draw](48,1) to[closed,curve through={(50,3) -- (52,4) -- (51,6) -- (47,6) -- (46.6,5) -- (45,3.8) }] (48,1);
\node[draw,circle,fill=magenta,minimum width=2cm] (n1) at (50,3) {};
\end{scope}
\node[inner sep=1pt,fill,circle,label={below right: $x_0$}] at (50,3){};
\draw[->,shorten <= -4mm] (n1.90) -- +(0.7,0.7) node[pos=1.3]{$\Omega_1 \cap \Omega$};
\draw[->] (51,6) -- +(0.7,0.3) node[pos=1.3]{$\Omega$};
\draw[->] (n1.300) -- +(0.7,-0.3) node[pos=1.3]{$\Omega_1$};
\draw[->] (n1.10) to[bend left] node[midway,below]{$\tau$} (n.120);
\end{tikzpicture}

\end{document}

答案1

回答完这个问题后,我发现楼主在后面的评论中已经回答了这个问题Harish Kumar 的回答回答之前的问题。事实上,我下面的回答对原帖作者来说非常清楚。我不确定这里真正的问题是什么,但我确信这不是我所问和回答的问题。

[也许问题应该是,没有 Hobby 怎么能做到这一点?或者也许应该是,我该如何安装 Hobby?当然,除非存在其他特定问题,否则第二个将是重复的。]

有两个问题。第一个问题是您尚未加载库hobby,但正在尝试使用其选项。第二个问题是您无法--在 中使用curve through。有关详细信息,请参阅 Hobby 手册。

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{shapes.geometric,hobby}
\begin{document}
\begin{tikzpicture}
  \draw[thick,->] (52,0) -- (60,0) node[anchor=north west] {$x'$};
  \draw[thick,->] (56,-03) -- (56,03) node[anchor=south east] {$x_N$};
  \node[draw=red,dashed,thick,semicircle,minimum width=4cm] (n) at (56,0.8) {};
  \node[draw=blue, dashed,thick,semicircle,minimum width=2cm] (n2) at (56,0.4) {};
  \node[draw=green,circle,minimum width=4cm] (n3) at (56,0) {};

  \draw (56,0) node[below right] {$O$} node{$\bullet$};
  \draw (58,0) node[below right] {\color{red} $1$} node{};
  \draw (54,0) node[below left] {\color{red} -$1$} node{};
  \draw (56.8,0) node[below right] {\color{blue} $r$} node{};
  \draw (55.3,0) node[below left] {\color{blue} -$r$} node{};

  \draw[red, ->] (n.400) -- +(0.7,0.3) node[pos=1.7]{\color{red} $I^{+}(1)$};
  \draw[green, ->] (n3.300) -- +(0.7,-0.3) node[pos=1.5]{\color{green}$I(1)$};
  \draw[red, ->] (n.210) -- +(-0.7,-2.3) node[pos=1.2]{\color{red}$\Gamma_1$};
  \draw[blue, ->] (n2.320) -- +(0.2,-0.5) node[pos=1.5]{\color{blue}$\Gamma_{r}$};

  \node[draw,circle,minimum width=2cm] (n1) at (50,3) {};
  \begin{scope}
    \clip[draw](48,1) to[closed,curve through={(50,3) .. (52,4) .. (51,6) .. (47,6) .. (46.6,5) .. (45,3.8) }] (48,1);
    \node[draw,circle,fill=magenta,minimum width=2cm] (n1) at (50,3) {};
  \end{scope}
  \node[inner sep=1pt,fill,circle,label={below right: $x_0$}] at (50,3){};
  \draw[->,shorten <= -4mm] (n1.90) -- +(0.7,0.7) node[pos=1.3]{$\Omega_1 \cap \Omega$};
  \draw[->] (51,6) -- +(0.7,0.3) node[pos=1.3]{$\Omega$};
  \draw[->] (n1.300) -- +(0.7,-0.3) node[pos=1.3]{$\Omega_1$};
  \draw[->] (n1.10) to[bend left] node[midway,below]{$\tau$} (n.120);
\end{tikzpicture}
\end{document}

爱好代码

相关内容