制作洛书魔方

制作洛书魔方

我正在写一篇关于魔方的论文,我想在其中加入洛书魔方,但我想使用 XeLaTeX 来实现,而不是只添加一张图片。以下图片是我想要制作的: 在此处输入图片描述

有人知道如何制作上面的内容吗?我认为可能需要使用 tikz 之类的东西,但我对 LaTeX 的掌握还不是很熟练。

答案1

这是一个可能的解决方案。 使用pics来自的技术。它们被定义为和,两者都以节点数作为输入,然后条件检查将确定使用哪个代码在页面周围绘制图像,包括中心图像。如果给定坐标,每个都可以分配到页面上的任何位置。tikz 3.0myboxmylinepic

在此处输入图片描述

代码

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{%
pics/.cd,
mybox/.style args={#1}{
code={  % all node required are defined first.
\node (d1) at (0,0){};\node (d2) at (0,1){};
\node (d5) at (0,2){};\node (d7) at (0,3){};
\node (d8) at (1,3){};\node (d6) at (1,2){};
\node (d3) at (1,1){};\node (d4) at (1,0){};
\ifnum #1=2
\foreach \i in {1,2,...,#1}
\draw[very thick,fill=black] (d\i) circle (0.5em);  
\foreach \i/\j in {1/2}
\draw[very thick] (d\i) -- (d\j);
\else
\ifnum #1=4
\foreach \i in {1,2,...,#1}
\draw[very thick,fill=black] (d\i) circle (0.5em);  
\foreach \i/\j in {1/2,2/3,3/4,4/1}
\draw[very thick] (d\i)--(d\j);
\else
\ifnum #1=6
\foreach \i in {1,2,...,#1}
\draw[very thick,fill=black] (d\i) circle (0.5em);  
\foreach \i/\j in {1/2,2/5,5/6,6/3,3/4,4/1}
\draw[very thick] (d\i)--(d\j);
\else
\ifnum #1=8
\foreach \i in {1,2,...,#1}
\draw[very thick,fill=black] (d\i) circle (0.5em);  
\foreach \i/\j in {1/2,2/5,5/7,7/8,8/6,6/3,3/4,4/1}
\draw[very thick] (d\i)--(d\j);
\fi
\fi
\fi
\fi
}},

myline/.style args={#1}{
code={ % all node required are defined first
\node (d1) at (0,0){};
\node (d2) at (1,0){};  \node (d3) at (-1,0){ };
\node (d4) at (2,0){};  \node (d5) at (-2,0){ };
\node (d6) at (3,0){};  \node (d7) at (-3,0){ };
\node (d8) at (4,0){};  \node (d9) at (-4,0){ };
\ifnum #1=1
\foreach \i in {1,...,#1}
\draw[fill=white,line width=2pt] (d\i) circle (0.6em);  
\else
\ifnum #1=3
\foreach \i/\j in {1/2,1/3}
\draw[very thick] (d\i)--(d\j);
\foreach \i in {1,...,#1}
\draw[fill=white,line width=2pt] (d\i) circle (0.6em);  
\else
\ifnum #1=5
\foreach \i/\j in {1/2,1/3}
\draw[very thick] (d\i)--(d\j);
\foreach \i in {1,...,3}{
\draw[fill=white,line width=2pt] (d\i) circle (0.6em);} 
\else
\ifnum #1=7
\foreach \i/\j in {1/3,3/5,5/7,1/2,2/4,4/6}
\draw[very thick] (d\i)--(d\j);
\foreach \i in {1,...,#1}
\draw[fill=white,line width=2pt] (d\i) circle (0.6em);  
\else
\ifnum #1=9    
\foreach \i/\j in {1/2,2/4,4/6,6/8,1/3,3/5,5/7,7/9}
\draw[very thick] (d\i)--(d\j);
\foreach \i in {1,...,#1}
\draw[fill=white,line width=2pt] (d\i) circle (0.6em);  
\fi
\fi
\fi
\fi
\fi
}},
}

\begin{tikzpicture}
    \pic[rotate=45]  at (0,0)      {mybox={4}};
    \pic[rotate=-45] at (10,0)     {mybox={2}};
    \pic[rotate=45]  at (10,-10)   {mybox={6}};
    \pic[rotate=-45] at (0,-9)     {mybox={8}};
    \pic[]           at (5,-9)     {myline={1}};
    \pic[rotate=90]  at (0,-4)     {myline={3}};
    \pic[]           at (5,-4)     {myline={5}};
    \pic[rotate=90]  at (5,-4)     {myline={5}};
    \pic[rotate=90]  at (10,-4)    {myline={7}};
    \pic[]           at (5.5,1)    {myline={9}};
\end{tikzpicture}
\end{document}

答案2

带有以下内容的简短代码pst-node:我定义\hbeads\vbeads和宏并将元素放在:dominocrosspsmatrix

\documentclass[pdf, x11names]{article}%

\usepackage{pst-node, multido}
\newcommand\domino[2][]{%
\fpSub{#2}{1}{\lastB}\def\ori{\numexpr-\lastB/2\relax}\psset{#1}
\multido{\n=0+1}{#2}{\dotnodes(\n,0){A\n}(\n,1){B\n}}\psframe(A0)(B\lastB)
}%

\newcommand\cross[1][]{\psset{#1}
\dotnodes(0,0){O}(0,1){A}(-1,0){B}(0,-1){C}(1,0){D}
\ncline{O}{A}\ncline{O}{B}\ncline{O}{C}\ncline{O}{D}}
%
\newcommand\hbeads[2][]{\def\lastB{\numexpr#2 - 1\relax}\def\ori{\numexpr-\lastB/2\relax}\psset{#1} \multips(\ori,0)(1,0){\lastB}{\psline{o-o}(0,0)(1,0)}}%
%
\newcommand\vbeads[2][]{\def\lastB{\numexpr#2 - 1\relax}\def\ori{\numexpr-\lastB/2\relax}\psset{#1} \multips(0,\ori)(0,1){\lastB}{\psline{o-o}(0,0)(0,1)}}%

\begin{document}

\psset{linewidth=1pt, linecolor=Red3, dotsize=7pt, showpoints=true}%
\begin{pspicture}
 \begin{psmatrix}[colsep =4,rowsep =4cm]
 \rput[bl]{-45}(0,-0.71){\domino[xunit = 1.25,yunit = 0.9]{2}}& \hbeads[unit=0.5]{9}& \rput{135}{\domino[yunit = 1.2]{1}}\\%
\vbeads{3} & \cross & \vbeads{7}\\ %(-2,0)
\rput[t]{45}(0,-0.71){\domino[unit = 0.8]{4}} &\psdot[dotstyle=Bo](0,0) &\rput{135}{\domino[unit = 0.8]{3}}
 \end{psmatrix}
\end{pspicture}

\end{document} 

在此处输入图片描述

相关内容