在 LaTeX 中排版七巧板图形

在 LaTeX 中排版七巧板图形

有没有可以在 LaTeX 中排版七巧板图形的软件包?示例图形如下:

(不显示晒黑)

问题

(展示晒黑的部分)

解决方案

答案1

您没有说明要如何指定七巧板图,如果没有说明,就很难知道如何最好地回答您的问题。话虽如此,我偶尔也想自己制作一些图,因此我发布了代码,希望它能有所帮助。

它使用 TikZ 并制作碎片的图片。然后可以将它们放置以形成图表。图片只是代码绘制形状的快捷方式,没有任何花哨的定位语法(例如“将大三角形放在中等三角形沿线”),因为我发现使用坐标(尽管通常是相对坐标)放置图块比沿现有图块放置位置要容易得多。为了允许花哨的定位,将它们转换为节点可能更好。对于我所做的事情,这比它值得的麻烦更多。

主要有两种风格:tangram puzzletangram solution。主要区别在于tangram solution用白色较粗的线条绘制瓷砖的边缘,从而勾勒出它们的轮廓。

\documentclass{article}
%\url{https://tex.stackexchange.com/q/407449/86}
\usepackage[scale=.8]{geometry}
\thispagestyle{empty}
\pagestyle{empty}
\usepackage{tikz}

\tikzset{
  big triangle/.pic={
  \path[pic actions] (0,0) -- (2,0) -- (2,2) -- cycle;
  },
  medium triangle/.pic={
    \path[pic actions] (0,0) -- (1,1) -- (2,0) -- cycle;  
  },
  square/.pic={
    \path[pic actions] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
  },
  small triangle/.pic={
    \path[pic actions] (0,0) -- (1,0) -- (1,1) -- cycle;
  },
  parallelogram/.pic={
    \path[pic actions] (0,0) -- (1,0) -- (2,1) -- (1,1) -- cycle;
  }
}

\tikzset{
  tangram puzzle/.style={
    fill=black,
    draw=black
  },
  tangram solution/.style={
      fill=black,
    draw=white,
    line width=1mm
  },   
  tangram/.style={
  transform shape,
    %tangram puzzle
    tangram solution
  }
}

\begin{document}
\centering

\vspace*{\fill}

\begin{tikzpicture}[scale=4]
\pic[tangram] at (0,0) {big triangle};
\pic[tangram,rotate=-90] at (2,2) {big triangle};
\pic[tangram,rotate=-90] at (2,0) {square};
\pic[tangram,rotate=180] at (4,0) {small triangle};
\pic[tangram,rotate=90] at (2,-1) {small triangle};
\pic[tangram,xscale=-1] at (2,-1) {parallelogram};
\pic[tangram,rotate=180] at (3,-1) {medium triangle};
\end{tikzpicture}

\vspace*{\fill}

\newpage

\vspace*{\fill}

\begin{tikzpicture}[scale=3.5]
\path (0,-1) pic[tangram] {small triangle}
++(1,0) pic[tangram] {square}
++(1,1) pic[tangram,rotate=-45,yscale=-1] {big triangle}
++(-45:2) pic[tangram,rotate=-135] {big triangle}
+({-sqrt(2)},0) pic[tangram,rotate=-135] {parallelogram}
++(-2,{-2*sqrt(2)}) pic[tangram] {medium triangle}
++(2,1) pic[tangram,rotate=-90] {small triangle}
;
\end{tikzpicture}

\vspace*{\fill}

\newpage

\vspace*{\fill}

\begin{tikzpicture}[scale=3.5]
\path (6,0) pic[tangram,rotate=45] {small triangle}
pic[tangram,rotate=-45] {square}
pic[tangram,rotate=-45,yscale=-1] {big triangle}
++(-45:2) pic[tangram,rotate=-135] {big triangle}
+({-sqrt(2)},0) pic[tangram,rotate=-135] {parallelogram}
++(-2,{-2*sqrt(2)}) pic[tangram] {medium triangle}
++(2,1) pic[tangram,rotate=-90] {small triangle}
;
\end{tikzpicture}

\vspace*{\fill}
\newpage
\vspace*{\fill}

\begin{tikzpicture}[scale=3.5]
\path (9,{1/sqrt(2)}) pic[tangram,rotate=-45] {small triangle}
++(-45:1) pic[tangram,rotate=-45] {square}
pic[tangram,rotate=-45,yscale=-1] {big triangle}
++(-45:2) pic[tangram,rotate=-135] {big triangle}
+({-sqrt(2)},0) pic[tangram,rotate=-135] {parallelogram}
++(-2,{-2*sqrt(2)}) pic[tangram] {medium triangle}
++(2,1) pic[tangram,rotate=-90] {small triangle}
;
\end{tikzpicture}

\vspace*{\fill}
\newpage
\vspace*{\fill}

\begin{tikzpicture}[scale=3.5]
\path (0,0) pic[tangram] {big triangle}
++(2,2) pic[tangram,rotate=180] {big triangle}
++(0,1) pic[tangram,rotate=-90] {small triangle}
++(-1,-1) pic[tangram] {square}
++(-1,0) pic[tangram] {small triangle}
++(-1,0) pic[tangram] {parallelogram}
++(1,1) pic[tangram] {medium triangle}
;
\end{tikzpicture}

\vspace*{\fill}
\newpage
\vspace*{\fill}

\begin{tikzpicture}[scale=3,rotate=90]
\path (0,0) pic[tangram,rotate=-90] {small triangle}
++(-1,-1) pic[tangram] {square}
++(-1,0) pic[tangram] {small triangle}
++(-1,0) pic[tangram] {parallelogram}
++(1,1) pic[tangram] {medium triangle}
++({-1-sqrt(2)},{-1+sqrt(2)}) pic[tangram,rotate=-45] {big triangle}
++(4,0) pic[tangram,rotate=-45] {big triangle}
;
\end{tikzpicture}

\vspace*{\fill}
\newpage
\vspace*{\fill}

\begin{tikzpicture}[scale=3]
\path (0,0) pic[tangram,rotate=180] {medium triangle}
++(-1,-1) pic[tangram] {parallelogram}
++(1,0) pic[tangram] {small triangle}
++(1,0) pic[tangram] {square}
++(2,1) pic[tangram,rotate=180] {small triangle}
++(-2.5,.1) pic[tangram,rotate=80] {big triangle}
++(80:4)
++(170:2) pic[tangram,rotate=-100] {big triangle}
;
\end{tikzpicture}
\end{document}

以下是其中一个输出:

七巧板企鹅

相关内容