我想改变白球和黑球的数量。如标题所示,我还试图在相同颜色的球之间画一条线,并在颜色相反的球之间画一条虚线。我尝试在下面的 MWE 中执行此操作。但是我不确定如何让 latex 知道是在两个球之间画一条虚线还是一条单线。有什么想法吗?
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
% create the node
\pgfmathsetmacro\white{3}
\pgfmathsetmacro\black{2}
\pgfmathsetmacro\n{\white+\black}
\node[draw=none,minimum size=2cm,regular polygon,regular polygon sides=\n] (a) {};
% draw a black dot in each vertex
\foreach \x in {1,2,...,\n}
\fill (a.corner \x) circle[radius=2.2pt];
% draw a black dot in each vertex
\foreach \x in {1,2,...,\white}
\fill[color=white] (a.corner \x) circle[radius=2pt];
\end{tikzpicture}
\end{document}
答案1
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
% create the node
\pgfmathsetmacro\white{9}
\pgfmathsetmacro\black{4}
\pgfmathsetmacro\whiteplusone{int(\white+1)}
\pgfmathsetmacro\n{\white+\black}
\node[draw=none,minimum size=2cm,regular polygon,regular polygon sides=\n] (a) {};
% draw edges
\foreach\x in{1,...,\n}{
\foreach\y in{\x,...,\n}{
\pgfmathsetmacro\tempdimen{(\x-\white-.5)*(\y-\white-.5)}
\ifdim\tempdimen pt>0pt
\draw(a.corner \x)--(a.corner \y);
\else
\draw[dashed](a.corner \x)--(a.corner \y);
\fi
}
}
% draw a white dot in each vertex
\foreach \x in {1,...,\white}
\fill (a.corner \x) circle[radius=2pt];
% draw a black dot in each vertex
\foreach \x in {\whiteplusone,...,\n}
\draw[fill=white](a.corner \x) circle[radius=2pt];
\end{tikzpicture}
\end{document}
只是说...也许你需要这下一个。