Tikz:填写失败

Tikz:填写失败

我刚刚开始使用 tikz 包,正在使用 tikzpicture 对图形和图形上的复合体进行一些操作。我希望能够填充图形的某些区域。我找到了我想要的东西,但有一件事让我很烦恼(参见代码和图片)。

 \begin{tikzpicture}
  \tikzstyle{vertex}=[draw,circle, fill = black, inner sep = 1.5pt] 
  \node[vertex] (1) [label = right:$a$] at (0,0) {};
  \node[vertex] (2) [label = right:$b$] at (3,0) {};
  \node[vertex] (3) [label = right:$c$] at (1,1.5) {};
  \node[vertex] (4) [label = above:$d$] at (1,3) {};
  \node[vertex] (5) [label = below:$e$] at (0,-2) {};
  \node[vertex] (6) [label = below:$f$] at (2,-2) {};
  \draw[fill=gray] (3) to (4) to [out=180,in=90] (-1.5,0) to [out=-90,in=135] (5) to [out=90,in=-90] (-0.5,0) to [out=90,in=180] (3);
\end{tikzpicture}

在此处输入图片描述

在边缘 cd 处,有一个条带没有填满,而我希望它被填满。对这个问题有什么建议或解决方案吗?我错过了什么吗?我可以做点不同的事情吗?提前致谢。

答案1

我想,你喜欢获得以下图片:

在此处输入图片描述

从下面的代码中你可以看到,坐标由 决定.center。如果没有这个,它将被视为节点形状边框上的锚点之一。为了填充节点下的区域,我还使用了“背景库”。

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

    \begin{document}
 \begin{tikzpicture}
  \tikzstyle{vertex}=[draw,circle, fill = black, inner sep = 1.5pt]
  \node[vertex] (1) [label = right:$a$] at (0,0) {};
  \node[vertex] (2) [label = right:$b$] at (3,0) {};
  \node[vertex] (3) [label = right:$c$] at (1,1.5) {};
  \node[vertex] (4) [label = above:$d$] at (1,3) {};
  \node[vertex] (5) [label = below:$e$] at (0,-2) {};
  \node[vertex] (6) [label = below:$f$] at (2,-2) {};
\scoped[on background layer]
  \draw[fill=gray] (3.center) to (4.center) to [out=180,in=90] (-1.5,0) to [out=-90,in=135] (5.center) to [out=90,in=-90] (-0.5,0) to [out=90,in=180] (3.center);
\end{tikzpicture}
    \end{document}

答案2

其他方式

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

\begin{document}
 \begin{tikzpicture}

  \path coordinate["$a$"  right] (1)  at (0,0) 
        coordinate["$b$"  right] (2)  at (3,0) 
        coordinate["$c$"  right] (3)  at (1,1.5) 
        coordinate["$d$"  above] (4)  at (1,3) 
        coordinate["$e$"  below] (5)  at (0,-2) 
        coordinate["$f$"  below] (6)  at (2,-2) ;

  \draw[fill=gray] (3) to (4) 
                       to [out=180,in=90] (-1.5,0) 
                       to [out=-90,in=135] (5) 
                       to [out=90,in=-90] (-0.5,0) 
                       to [out=90,in=180] (3);

  \foreach \c in {1,...,6}{\fill (\c) circle (1.5 pt); }

\end{tikzpicture}
 \end{document}

在此处输入图片描述

相关内容