更新

更新

是否有一个LaTeX软件包可以让我绘制多米诺骨牌而不必单独绘制每一块tikz

答案1

我已经拥有这个代码很长一段时间了,也许它可以作为更好实现的灵感:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\tikzset{
  dot hidden/.style={},
  line hidden/.style={},
  dot colour/.style={dot hidden/.append style={color=#1}},
  dot colour/.default=black,
  line colour/.style={line hidden/.append style={color=#1}},
  line colour/.default=black
}

\usepackage{xparse}

\NewDocumentCommand{\domino}{mm}{
\begin{tikzpicture}[x=2em,y=2em,radius=0.1]
\draw[rounded corners=0.5,line hidden] (0,0) rectangle (1,2);

\draw[line hidden] (0,1) -- (1,1);
\ifodd#1
  \fill[dot hidden] (0.5,1.5) circle;
\fi
\ifnum#1>1
   \fill[dot hidden] (0.2,1.2) circle;
   \fill[dot hidden] (0.8,1.8) circle; 
   \ifnum#1>3
      \fill[dot hidden] (0.8,1.2) circle;
      \fill[dot hidden] (0.2,1.8) circle;   
   \fi
   \ifnum#1>5
      \fill[dot hidden] (0.2,1.5) circle;
      \fill[dot hidden] (0.8,1.5) circle;  
   \fi
\fi
\ifodd#2
   \fill[dot hidden] (0.5,0.5) circle;
\fi
\ifnum#2>1
   \fill[dot hidden] (0.2,0.2) circle;
   \fill[dot hidden] (0.8,0.8) circle;
   \ifnum#2>3
      \fill[dot hidden] (0.8,0.2) circle;
      \fill[dot hidden] (0.2,0.8) circle;   
   \fi
   \ifnum#2>5
      \fill[dot hidden] (0.2,0.5) circle;
      \fill[dot hidden] (0.8,0.5) circle;  
   \fi
\fi
\end{tikzpicture}
}

\begin{document}

\domino{0}{0}
\domino{0}{1}
\domino{0}{2}
\domino{0}{3}
\domino{0}{4}
\domino{0}{5}
\domino{0}{6}

\domino{1}{0}
\domino{1}{1}
\domino{1}{2}
\domino{1}{3}
\domino{1}{4}
\domino{1}{5}
\domino{1}{6}

\domino{2}{0}
\domino{2}{1}
\domino{2}{2}
\domino{2}{3}
\domino{2}{4}
\domino{2}{5}
\domino{2}{6}

\domino{3}{0}
\domino{3}{1}
\domino{3}{2}
\domino{3}{3}
\domino{3}{4}
\domino{3}{5}
\domino{3}{6}

\domino{4}{0}
\domino{4}{1}
\domino{4}{2}
\domino{4}{3}
\domino{4}{4}
\domino{4}{5}
\domino{4}{6}

\domino{5}{0}
\domino{5}{1}
\domino{5}{2}
\domino{5}{3}
\domino{5}{4}
\domino{5}{5}
\domino{5}{6}

\domino{6}{0}
\domino{6}{1}
\domino{6}{2}
\domino{6}{3}
\domino{6}{4}
\domino{6}{5}
\domino{6}{6}

\end{document}

输出:

嘎嘎

希望能帮助到你。:)

答案2

另外一个选择:

在此处输入图片描述

只需用来\Domino{<number>}{<number>}绘制瓷砖;调整\DominoWd瓷砖以获得所需的尺寸。

代码:

\documentclass[varwidth=13.6cm,border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.multipart,positioning,shadows}

\newlength\DominoWd
\setlength\DominoWd{1cm}
\newsavebox\mybox

\newcommand\PlaceDot[2]{
\fill[white] ([shift={(#1\DominoWd,#2\DominoWd)}]0,0) circle [radius=0.1\DominoWd];
}

\newcommand\domino[1]{%
\tikz[overlay]
{
\ifcase#1\relax
\or
\PlaceDot{0}{0}
\or
\PlaceDot{-0.3}{0.3}\PlaceDot{0.3}{-0.3}
\or
\PlaceDot{-0.3}{0.3}\PlaceDot{0}{0}\PlaceDot{0.3}{-0.3}
\or
\PlaceDot{-0.3}{0.3}\PlaceDot{0.3}{0.3}\PlaceDot{-0.3}{-0.3}\PlaceDot{0.3}{-0.3}
\or
\PlaceDot{-0.3}{0.3}\PlaceDot{0.3}{0.3}\PlaceDot{0}{0}\PlaceDot{0.3}{-0.3}\PlaceDot{-0.3}{-0.3}
\or
\PlaceDot{-0.3}{0.3}\PlaceDot{0.3}{0.3}\PlaceDot{-0.3}{0}\PlaceDot{0.3}{0}\PlaceDot{0.3}{-0.3}\PlaceDot{-0.3}{-0.3}
\fi}%
}

\newcommand\Domino[3][]{%
\begin{tikzpicture}[#1]
\node[
  rectangle split,
  rectangle split parts=2,
  fill=black,
  text width=\DominoWd,
  align=center,
  text=white,
  drop shadow={black!20,opacity=1},
  rounded corners=0.13\DominoWd,
  #1
  ] 
  (dom)
  {%
    \rule[-0.5\DominoWd]{0pt}{\DominoWd}\domino{#2}%
    \nodepart{two}\rule[-0.5\DominoWd]{0pt}{\DominoWd}\domino{#3}%
  };
\draw[white!80!black]
  ([xshift=0.1\DominoWd]dom.west) -- ([xshift=-0.1\DominoWd]dom.east);
\end{tikzpicture}%
}

\begin{document}

\foreach \Valora in {0,...,6}
  {%
    \foreach \Valorb in {0,...,6}
      {\Domino{\Valora}{\Valorb}\quad}\par\medskip%
   }%   

\end{document}

更新

使用链条很容易排版出一个真正的多米诺骨牌游戏:

在此处输入图片描述

代码:

\documentclass[varwidth=13.6cm,border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.multipart,positioning,shadows,chains,scopes}

\newlength\DominoWd
\setlength\DominoWd{1cm}
\newsavebox\mybox

\newcommand\PlaceDot[2]{
\fill[white] ([shift={(#1\DominoWd,#2\DominoWd)}]0,0) circle [radius=0.08\DominoWd];
}

\newcommand\domino[1]{%
\tikz[overlay]
{
\ifcase#1\relax
\or
\PlaceDot{0}{0}
\or
\PlaceDot{-0.3}{0.3}\PlaceDot{0.3}{-0.3}
\or
\PlaceDot{-0.3}{0.3}\PlaceDot{0}{0}\PlaceDot{0.3}{-0.3}
\or
\PlaceDot{-0.3}{0.3}\PlaceDot{0.3}{0.3}\PlaceDot{-0.3}{-0.3}\PlaceDot{0.3}{-0.3}
\or
\PlaceDot{-0.3}{0.3}\PlaceDot{0.3}{0.3}\PlaceDot{0}{0}\PlaceDot{0.3}{-0.3}\PlaceDot{-0.3}{-0.3}
\or
\PlaceDot{-0.3}{0.3}\PlaceDot{0.3}{0.3}\PlaceDot{-0.3}{0}\PlaceDot{0.3}{0}\PlaceDot{0.3}{-0.3}\PlaceDot{-0.3}{-0.3}
\fi}%
}

\newcounter{domtile}

\newcommand\Domino[3][]{%
\stepcounter{domtile}
\node[
  rectangle split,
  rectangle split parts=2,
  fill=black,
  text width=\DominoWd,
  align=center,
  text=white,
  outer sep=0pt,
  inner sep=0pt,
  %drop shadow={black!20,opacity=1},
  rounded corners=0.13\DominoWd,
  #1
  ] 
  (dom\thedomtile)
  {%
    \rule[-0.5\DominoWd]{0pt}{\DominoWd}\domino{#2}%
    \nodepart{two}\rule[-0.5\DominoWd]{0pt}{\DominoWd}\domino{#3}%
  };
\draw[white!80!black,shorten >= 0.11\DominoWd,shorten <= 0.11\DominoWd]
  (dom\thedomtile.west) -- (dom\thedomtile.east);
}

\newenvironment{dominogame}[1][]
  {\begin{tikzpicture}[#1]}
  {\end{tikzpicture}}

\begin{document}

\begin{dominogame}[start chain=1 going above,node distance=1pt,every node/.append style={on chain=1}]
\Domino[shift={(\DominoWd,0.5\DominoWd)},rotate=90]{6}{6}
\Domino[shift={(\DominoWd,0.5\DominoWd)}]{5}{6}
\Domino{2}{5}
\Domino{3}{2}
\Domino[shift={(0,2\DominoWd+1.5pt)},continue chain=1 going left,rotate=90]{1}{3}
\Domino[shift={(-2\DominoWd-1pt,\DominoWd)},rotate=90]{5}{1}
\Domino[shift={(-1.5\DominoWd-1pt,-2.5\DominoWd-1pt)},continue chain=1 going below,rotate=180]{0}{5}
\Domino{5}{0}
\Domino[shift={(-\DominoWd,-0.5\DominoWd)},rotate=90]{0}{0}
\Domino[shift={(-\DominoWd,-0.5\DominoWd)}]{0}{3}
\Domino{3}{6}
\Domino{6}{1}
\Domino[shift={(-\DominoWd,-0.5\DominoWd)},rotate=90]{1}{1}
{
[start chain=2 going below,every node/.append style={on chain=2}]
\Domino[shift={(0pt,-0.5\DominoWd)},at=(dom1)]{6}{4}
\Domino[shift={(0pt,-2\DominoWd-1.5pt)},continue chain=2 going right,rotate=90]{4}{0}
}
\end{dominogame}

\end{document}

答案3

只需使用缩放堆栈(无tikz)并进行调用即可\domino{<top>}{<bottom>}。“单位”框缩放到最终大小\domsz,当前设置为 1cm。正方形中点的相对大小通过改变\domwd(“单位”框的未缩放正方形大小,其中\bullet放置了 s )来控制,而点与未缩放框边缘的偏移量由 控制\domos。未缩放框的边框宽度为\fboxrule,可以更改。

请注意,项目\blt符号经过了改变,以便在字形的所有侧面上都有均匀的间距(要查看这一点,请尝试\fbox{\blt})。

\documentclass{article}
\usepackage{stackengine,scalerel}
\def\domsz{1cm}
\def\domwd{20pt}
\def\domos{1.8pt}
\def\blt{\stackon[.3pt]{$\bullet$}{}\kern-.3pt}
\def\domsq{\fboxsep=0pt\fbox{\rule{\domwd}{0pt}\rule{0pt}{\domwd}}}
\newcommand\domx[1]{\savestack\tmpbox{%
    \if0#1\domsq\else
    \if1#1\stackinset{c}{}{c}{}{\blt}{\domsq}\else
    \if2#1\stackinset{l}{\domos}{t}{\domos}{\blt}{%
      \stackinset{r}{\domos}{b}{\domos}{\blt}{\domsq}}\else
    \if3#1\stackinset{l}{\domos}{t}{\domos}{\blt}{%
      \stackinset{r}{\domos}{b}{\domos}{\blt}{%
      \stackinset{c}{}{c}{}{\blt}{\domsq}}}\else
    \if4#1\stackinset{l}{\domos}{t}{\domos}{\blt}{%
      \stackinset{r}{\domos}{b}{\domos}{\blt}{%
      \stackinset{l}{\domos}{b}{\domos}{\blt}{%
      \stackinset{r}{\domos}{t}{\domos}{\blt}{\domsq}}}}\else
    \if5#1\stackinset{l}{\domos}{t}{\domos}{\blt}{%
      \stackinset{r}{\domos}{b}{\domos}{\blt}{%
      \stackinset{l}{\domos}{b}{\domos}{\blt}{%
      \stackinset{r}{\domos}{t}{\domos}{\blt}{%
      \stackinset{c}{}{c}{}{\blt}{\domsq}}}}}\else
    \if6#1\stackinset{l}{\domos}{t}{\domos}{\blt}{%
      \stackinset{r}{\domos}{c}{}{\blt}{%
      \stackinset{l}{\domos}{c}{}{\blt}{%
      \stackinset{r}{\domos}{b}{\domos}{\blt}{%
      \stackinset{l}{\domos}{b}{\domos}{\blt}{%
      \stackinset{r}{\domos}{t}{\domos}{\blt}{\domsq}}}}}}\else
    \fi\fi\fi\fi\fi\fi\fi}\ignoremathstyle\scaleto{\tmpbox}{\domsz}%
}
\newcommand\domino[2]{\stackon[-\fboxrule]{\domx{#2}}{\domx{#1}}}
\begin{document}
\domino{1}{3} \domino{2}{4} \domino{0}{6} \domino{5}{5}\par
\domino{3}{4} \domino{4}{6} \domino{6}{2} \domino{5}{1}
\end{document}

在此处输入图片描述

例如,简单地改变\fboxrule=1pt\def\domwd{17pt}将产生

在此处输入图片描述

答案4

可以不包含任何类型的图形,tikz或者任何其他包装吗?

姆韦

\documentclass[a5paper]{article}
\font\domino=domino
\catcode`\^=12 \offinterlineskip
\parskip.5em\parindent0pt
\begin{document}\tiny
Domino tiles:\par
{\domino<12} {\domino<34} {\domino5>0} \dots even  {\domino8>9}\par 
Starting the game:\par
{\domino<65<52<24<46<66}\par 
Watching your game:\par
{\domino ^1^24\\1v2v3}\par
Domino wall:\par
\obeylines\domino 
  <62<13^4\parskip0pt
  ^1^3<3>4v4
  v2v5<5>6<11
\end{document}

或者,使用包graphicxhhcount花式计数器):

姆韦

\documentclass[12pt,a5paper]{article}
\usepackage{hhcount} %http://tug.ctan.org/tex-archive/usergrps/uktug/baskervi/5_5/
\usepackage{graphicx} 
\def\dm#1#2{\mbox{\fcdice{#1}\rule{.05ex}{.75em}\fcdice{#2}}}
\def\md#1#2{\smash{\raisebox{-.35em}{\rotatebox{90}{\dm#1#2}}}}
\def\vd#1#2{\rotatebox{90}{\dm#1#2}}
\begin{document}
\Huge\parskip0pt\parindent0pt
\dm23 \dm35 \md55 \dm54\md44\dm40\\
\vd16 \dm13\md33 \dm34 \dm41\md11\vd10
\end{document}

注意:hhcount需要hhutils0可在同一个网络目录中找到。

相关内容