# Filling a polygon defined by \node command

I draw a polygon using \node in TikZ, and I want to fill the polygon.

When I use this method, it obviously fails because I do not use \coordinate to create the polygon.

Is there a way to fill a polygon drawn using \node, instead of \coordinate?

MWE:

\documentclass[11pt]{article}
\usepackage{amsthm,tikz,subcaption}

\begin{document}
\begin{figure}[t]
\centering
\begin{tikzpicture}[scale=8]
\tikzstyle{every node}=[draw, fill=white, shape=circle, minimum size=3pt,inner sep=1pt];
\tikzstyle{every path}=[draw, line width=0.3mm, color=red];
\node (v1) at (2.2,1) {};
\node (v2) at (2.8,1.3) {};
\node (v3) at (2.8,1.5) {};
\node (v4) at (2.2,1.6) {};
\node (v5) at (1.8,2) {};
\node (v6) at (1.8,1.5) {};
\node (v7) at (2.1,1.4) {};
\draw (v1)--(v2)--(v3)--(v4)--(v5)--(v6)--(v7)--(v1);

\fill [opacity=0.5,gray]
(v1) \foreach \i in {2,...,7}{ -- (v\i) } -- cycle;
\end{tikzpicture}
\caption{A simple polygon.}
\label{fig:vgPoints}
\end{figure}

\end{document}


Output:

Just the idea : use the centers of the points created by the nodes and connect them with a draw command and a fill=yourColor with opacity or not.

\documentclass[11pt]{article}
\usepackage{amsthm,tikz,subcaption}

\begin{document}
\begin{figure}[t]
\centering
\begin{tikzpicture}[scale=8]
\tikzstyle{every node}=[draw, fill=white, shape=circle, minimum size=3pt,inner sep=1pt];
\tikzstyle{every path}=[draw, line width=0.3mm, color=red];
\node (v1) at (2.2,1) {};
\node (v2) at (2.8,1.3) {};
\node (v3) at (2.8,1.5) {};
\node (v4) at (2.2,1.6) {};
\node (v5) at (1.8,2) {};
\node (v6) at (1.8,1.5) {};
\node (v7) at (2.1,1.4) {};
\draw[opacity=0.5,fill=gray] (v1.center)--(v2.center)--(v3.center)--(v4.center)--(v5.center)--(v6.center)--(v7.center)--(v1.center);

\fill [opacity=0.5,gray]
(v1) \foreach \i in {2,...,7}{ -- (v\i) } -- cycle;
\end{tikzpicture}
\caption{A simple polygon.}
\label{fig:vgPoints}
\end{figure}

\end{document}


• Welcome... Happy TeXing – koleygr Dec 12 '17 at 19:51