使用 TikZ 构建显示连接节点环的图形

使用 TikZ 构建显示连接节点环的图形

我想用 7 个节点和 8 个节点重现这个图形(见下文),但由于我从未在 LaTeX 中构建过图形,所以我毫无头绪。

在此处输入图片描述

答案1

这是百万分之一的方法。您可以使用极坐标。这是您提供的数字,现在您的任务是减少每个多边形的边数,即循环进行一些更改\foreach。这只需要非常简单的数学运算,对吗?

\documentclass[tikz,margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \i in {90,54,...,-234} {
    \draw (\i:2)--({\i-36}:2);
}
\foreach \i in {90,18,...,-198} {
    \draw[fill=black] (\i:2) circle (1mm);
}
\foreach \i in {54,-18,...,-234} {
    \draw[fill=white] (\i:2) circle (1mm);
}
\begin{scope}[xshift=5cm]
\foreach \i in {90,50,...,-230} {
    \draw (\i:2)--({\i-40}:2);
    \draw[fill=black] (\i:2) circle (1mm);
}
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑1:

这是你想要的吗?

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{figure}[htbp]
    \centering
    \begin{tikzpicture}
    \foreach \i in {90,54,...,-234} {
        \draw (\i:2)--({\i-36}:2);
    }
    \foreach \i in {90,18,...,-198} {
        \draw[fill=black] (\i:2) circle (1mm);
    }
    \foreach \i in {54,-18,...,-234} {
        \draw[fill=white] (\i:2) circle (1mm);
    }
    \begin{scope}[xshift=5cm]
    \foreach \i in {90,50,...,-230} {
        \draw (\i:2)--({\i-40}:2);
        \draw[fill=black] (\i:2) circle (1mm);
    }
    \end{scope}
    \end{tikzpicture}
    \caption{Some caption}
    \label{my:figure}
\end{figure}
\lipsum[2]
\end{document}

在此处输入图片描述

答案2

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture} %draw 8 nodes with alternating colors
    \foreach[count=\i] \fillc in {black,white,black,white,black,white,black,white} {
            \draw[shorten <=2mm,shorten >=2mm] (\i/8*360:2)-- ({(\i-1)/8*360}:2);
            \node[minimum size=4mm,inner sep=0,circle,draw,fill=\fillc] (point\i) at ({\i/8*360}:2) {};
        }
\end{tikzpicture}

\begin{tikzpicture} %draw 7 nodes, all black
    \foreach[count=\i] \fillc in {black,black,black,black,black,black,black} {
            \draw[shorten <=2mm,shorten >=2mm] (\i/7*360:2)-- ({(\i-1)/7*360}:2);
            \node[minimum size=4mm,inner sep=0,circle,draw,fill=\fillc] (point\i) at ({\i/7*360}:2) {};
        }
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案3

使用 TiZ 库shapes

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}

\tikzset{whitecirc/.style={fill=white,draw=black,thick},
blackcirc/.style={draw=black,thick}
}
\begin{document}

\begin{tikzpicture}
\def\ptsize{1.5pt}   
    \node[draw,regular polygon,minimum height=3cm,minimum width=3cm,regular polygon sides=7](P) {};
    \foreach \t in {1,3,5,7}{
    \fill[whitecirc] (P.corner \t) circle (\ptsize);}
    \foreach \t in {2,4,6}{
    \fill[blackcirc] (P.corner \t) circle (\ptsize);}

    \begin{scope}[xshift=4cm]
    \node[draw,regular polygon,minimum height=3cm,minimum width=3cm,regular polygon sides=8](P) {};
    \foreach \t in {1,2,...,8}{
    \fill[blackcirc] (P.corner \t) circle (\ptsize);}
    \end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容