绘制五边形图和标签

绘制五边形图和标签

我正在尝试生成以下图表。谁绘制图表?

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}

\def\r{4pt}
\def\dy{1cm}
\tikzstyle{c}=[draw,circle,fill=black,minimum size=\r,inner sep=0pt, anchor=center]
\tikzstyle{d}=[draw,circle,fill=white,minimum size=\r,inner sep=0pt, anchor=center]

\begin{tikzpicture}
\pgfmathtruncatemacro{\Ncorners}{5}
\node[draw, regular polygon,regular polygon sides=\Ncorners,minimum size=2.5cm] 
(poly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \node[d,label=left:$x$] (poly\Ncorners-1\x) at (poly\Ncorners.corner \x){};
}
\end{tikzpicture}

在此处输入图片描述

答案1

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}

\def\r{4pt}
\def\dy{1cm}
\tikzset{c/.style={draw,circle,fill=black,minimum size=\r,inner sep=0pt,
anchor=center},
d/.style={draw,circle,fill=white,minimum size=\r,inner sep=0pt, anchor=center}}

\begin{tikzpicture}[font=\tiny]
\pgfmathtruncatemacro{\Ncorners}{5}
\node[draw, regular polygon,regular polygon sides=\Ncorners,minimum size=3cm] 
(poly\Ncorners) {};
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3.5cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){};
    \node (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){$x_\x$};
}

\foreach\X in {1,...,\Ncorners}{
\foreach\Y in {1,...,\Ncorners}{
\pgfmathtruncatemacro{\Z}{abs(mod(abs(\Ncorners+\X-\Y),\Ncorners)-2)}
\ifnum\Z=0
\draw (poly\Ncorners-\X) -- (poly\Ncorners-\Y);
\fi
}
}
\begin{scope}[xshift=6cm]
\pgfmathtruncatemacro{\Ncorners}{7}
\node[draw, regular polygon,regular polygon sides=\Ncorners,minimum size=3cm] 
(poly\Ncorners) {};
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3.5cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){};
    \node (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){$x_\x$};
}

\foreach\X in {1,...,\Ncorners}{
\foreach\Y in {1,...,\Ncorners}{
\pgfmathtruncatemacro{\Z}{abs(mod(abs(\Ncorners+\X-\Y),\Ncorners)-2)}
\ifnum\Z=0
\draw (poly\Ncorners-\X) -- (poly\Ncorners-\Y);
\fi
}
}
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

附加要求:顺时针标记。

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}

\def\r{4pt}
\def\dy{1cm}
\tikzset{c/.style={draw,circle,fill=black,minimum size=\r,inner sep=0pt,
anchor=center},
d/.style={draw,circle,fill=white,minimum size=\r,inner sep=0pt, anchor=center}}

\begin{tikzpicture}[font=\tiny]
\begin{scope}
\pgfmathtruncatemacro{\Ncorners}{5}
\node[draw, regular polygon,regular polygon sides=\Ncorners,minimum size=3cm] 
(poly\Ncorners) {};
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3.5cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \pgfmathtruncatemacro{\y}{90-(\x-1)*360/\Ncorners}
    \node[d] (poly\Ncorners-\x) at (\y:1.5){};
    \node (outerpoly\Ncorners-\x) at (\y:1.75){$x_\x$};
}

\foreach\X in {1,...,\Ncorners}{
\foreach\Y in {1,...,\Ncorners}{
\pgfmathtruncatemacro{\Z}{abs(mod(abs(\Ncorners+\X-\Y),\Ncorners)-2)}
\ifnum\Z=0
\draw (poly\Ncorners-\X) -- (poly\Ncorners-\Y);
\fi
}
}
\end{scope}

\begin{scope}[xshift=6cm]
\pgfmathtruncatemacro{\Ncorners}{7}
\node[draw, regular polygon,regular polygon sides=\Ncorners,minimum size=3cm] 
(poly\Ncorners) {};
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3.5cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \pgfmathtruncatemacro{\y}{90-(\x-1)*360/\Ncorners}
    \node[d] (poly\Ncorners-\x) at (\y:1.5){};
    \node (outerpoly\Ncorners-\x) at (\y:1.75){$x_\x$};
}
\foreach\X in {1,...,\Ncorners}{
\foreach\Y in {1,...,\Ncorners}{
\pgfmathtruncatemacro{\Z}{abs(mod(abs(\Ncorners+\X-\Y),\Ncorners)-2)}
\ifnum\Z=0
\draw (poly\Ncorners-\X) -- (poly\Ncorners-\Y);
\fi
}
}
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容