我正在尝试生成以下图表。谁绘制图表?
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{positioning}
\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}[font=\tiny]
\draw (0,0)
node [d] (C0) {}
foreach \i in {1}
{
-- (0,\dy+\r) node (C\i) [d] {}
};
\draw (C1) ++(\dy+\r,0)
node (C2) [d] {}
foreach \i in {3}
{
-- (\dy+\r,0) node (C\i) [d] {}
}
-- (C0)
(C1) -- (C2);
\end{tikzpicture}
\end{document}
答案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}{3}
\node[draw, regular polygon,regular polygon sides=\Ncorners,minimum size=3cm]
(poly\Ncorners) {};
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=4.5cm]
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
\node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){};
\node[d] (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){};
\draw (poly\Ncorners-\x) -- (outerpoly\Ncorners-\x);
}
\begin{scope}[xshift=5cm]
\pgfmathtruncatemacro{\Ncorners}{4}
\node[draw, regular polygon,regular polygon sides=\Ncorners,minimum size=3cm]
(poly\Ncorners) {};
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=4.5cm]
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
\node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){};
\node[d] (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){};
\draw (poly\Ncorners-\x) -- (outerpoly\Ncorners-\x);
}
\end{scope}
\begin{scope}[xshift=10cm]
\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=4.5cm]
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
\node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){};
\node[d] (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){};
\draw (poly\Ncorners-\x) -- (outerpoly\Ncorners-\x);
}
\end{scope}
\end{tikzpicture}
\end{document}
我利用这个机会用 来\tikzstyle
代替\tikzset
。
答案2
只是为了好玩,一个命令代码(只有一个;
)。
\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\tikz[
poly/.style={regular polygon,minimum size=3cm},
dot/.style={circle,inner sep=2pt,draw,fill=white}]
\foreach \N in {3,4,5}
\draw[regular polygon sides=\N,xshift=\N*7cm]
node[poly,draw](S){} node[poly,scale=1.5](T){}
foreach\i in{1,...,\N}{(S.corner \i) node[dot]{} -- (T.corner \i) node[dot]{}};
\end{document}