此外,我更愿意创建一个带有 9 个参数的命令,指定每个圆圈是否用相应的颜色着色或留白。
作为初步近似,我考虑使用 TIKZ 图库来实现此目的。
我从手册中复制了这个例子:
\documentclass[11pt,a4paper,onecolumn,openright,final,oneside]{memoir}
%===============================================
\settrims{0.cm}{0.cm}
\setbinding{0cm} % space for binding
\setlrmarginsandblock{*}{3cm}{1} % spine = edge. Edge=3cm
\setulmarginsandblock{3cm}{*}{1} % upper=lower. Upper=3cm
\checkandfixthelayout
\usepackage{tikz}
\usetikzlibrary{graphs}
\begin{document}
\tikz
\graph [nodes={draw, circle}, clockwise, radius=.75cm, empty nodes, n=8] {
subgraph C_n [name=inner] <->[shorten <=1pt, shorten >=1pt]
subgraph C_n [name=outer]
};
\end{document}
我本来期待这样的事情
任何帮助都将不胜感激!
答案1
我不确定我是否会为此使用图形绘制。您似乎非常清楚结果应该是什么样子,也就是说,我认为不需要布局算法。您建议的一种非常简单的宏如下。(固定颜色,模数可能很棘手。;-)
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\newcommand{\mymacro}[1]{
\begin{tikzpicture}
\pgfmathparse{\mycolors[1]}
\node[regular polygon,regular polygon sides=4,draw,minimum size=3cm,\pgfmathresult](square1){};
\pgfmathparse{\mycolors[0]}
\node[regular polygon,regular polygon sides=4,draw,minimum size=3cm,rotate=45,\pgfmathresult]
(square0){};
\foreach \X [count=\Y,evaluate=\Y as \Z using {int(mod(\Y+1,2))},
evaluate=\Y as \V using {int((\Y+1)/2)}] in {#1}
{\ifnum\Y=9
\pgfmathsetmacro{\mycolor}{\mycolors[2]}
\ifnum\X=1
\filldraw[\mycolor] (0,0) circle (3mm);
\else
\draw[thick,fill=white,draw=\mycolor] (0,0) circle (3mm);
\fi
\else
\pgfmathsetmacro{\mycolor}{\mycolors[\Z]}
\ifnum\X=1
\filldraw[\mycolor] (square\Z.corner \V) circle (3mm);
\else
\draw[thick,fill=white,draw=\mycolor] (square\Z.corner \V) circle (3mm);
\fi
\fi}
\end{tikzpicture}
}
\xdef\mycolors{{"black","red","cyan"}}
\mymacro{1,0,1,1,0,1,1,1,0}
\end{document}
0
和条目1
确定给定的圆是否已填充,第 9 个条目是中间的点。颜色存储在数组中\mycolors
。
答案2
这里介绍一种简单的绘制方法。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[thick]
\def\a{2}
\def\r{.5}
\fill[cyan] (0,0) circle(\r);
\begin{scope}[rotate=-135]
\draw[gray] (-\a,-\a) rectangle (\a,\a);
\filldraw (\a,-\a) circle(\r);
\filldraw (-\a,\a) circle(\r);
\filldraw (-\a,-\a) circle(\r);
\filldraw (\a,\a) circle(\r);
\end{scope}
\draw[red] (-\a,-\a) rectangle (\a,\a);
\filldraw[red] (\a,-\a) circle(\r);
\filldraw[red] (\a,\a) circle(\r);
\filldraw[red] (-\a,-\a) circle(\r);
\draw[red,fill=white] (-\a,\a) circle(\r);
\end{tikzpicture}
\end{document}