我想模仿第一页这个 pdf通过使用以下代码来完成制作数独网格的艰巨任务。
实际上这个问题只是将几个数独网格叠加起来,而不是单独绘制这些数独网格。
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,shapes}
\tikzset {
digit/.style = {
minimum height = 5mm,
minimum width = 5mm,
anchor = center
}
}
\newcounter{row}
\newcounter{col}
\newcommand\setrow[9]{
\setcounter{col}{1}
\foreach \n in {#1, #2, #3, #4, #5, #6, #7, #8, #9} {
\edef\x{\value{col} - 0.5}
\edef\y{9.5 - \value{row}}
\node[digit,name={\arabic{row}-\arabic{col}}] at (\x, \y) {\n};
\stepcounter{col}
}
\stepcounter{row}
}
\newcommand\shownumber{
\foreach \x in {1,2,3,4,5,6,7,8,9} {
\node[font=\tiny,color=gray] at (\x-0.5,9.5) {\x};
\node[font=\tiny,color=gray] at (-.5,9.5-\x) {\x};
}
}
\begin{document}
\begin{tikzpicture}[scale=.5]
\begin{scope}
\draw (0, 0) grid (9, 9);
\draw[very thick, scale=3] (0, 0) grid (3, 3);
\setcounter{row}{1}
\setrow { }{2}{ } {5}{ }{1} { }{9}{ }
\setrow {8}{ }{ } {2}{ }{3} { }{ }{6}
\setrow { }{3}{ } { }{6}{ } { }{7}{ }
\setrow { }{ }{1} { }{ }{ } {6}{ }{ }
\setrow {5}{4}{ } { }{ }{ } { }{1}{9}
\setrow { }{ }{2} { }{ }{ } {7}{ }{ }
\setrow { }{9}{ } { }{3}{ } { }{8}{ }
\setrow {2}{ }{ } {8}{ }{4} { }{ }{7}
\setrow { }{1}{ } {9}{ }{7} { }{6}{ }
\shownumber{}
\end{scope}
\end{tikzpicture}
\end{document}
答案1
类似下面的代码怎么样?我仅重用您的 nice tikzpicture
,制作白色背景,使用rotate
选项并与hspace
图片 vspace
叠加。
输出如下:
如果这对您有帮助,我相信您可以采用这个技巧来制作您想要的整个图片。
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,shapes}
\tikzset {
digit/.style = {
minimum height = 5mm,
minimum width = 5mm,
anchor = center
}
}
\newcounter{row}
\newcounter{col}
\newcommand\setrow[9]{
\setcounter{col}{1}
\foreach \n in {#1, #2, #3, #4, #5, #6, #7, #8, #9} {
\edef\x{\value{col} - 0.5}
\edef\y{9.5 - \value{row}}
\node[digit,name={\arabic{row}-\arabic{col}}] at (\x, \y) {\n};
\stepcounter{col}
}
\stepcounter{row}
}
\newcommand\shownumber{
\foreach \x in {1,2,3,4,5,6,7,8,9} {
\node[font=\tiny,color=gray] at (\x-0.5,9.5) {\x};
\node[font=\tiny,color=gray] at (-.5,9.5-\x) {\x};
}
}
\begin{document}
\begin{tikzpicture}[scale=.5]
\begin{scope}
\draw (0, 0) grid (9, 9);
\draw[very thick, scale=3] (0, 0) grid (3, 3);
\setcounter{row}{1}
\setrow { }{2}{ } {5}{ }{1} { }{9}{ }
\setrow {8}{ }{ } {2}{ }{3} { }{ }{6}
\setrow { }{3}{ } { }{6}{ } { }{7}{ }
\setrow { }{ }{1} { }{ }{ } {6}{ }{ }
\setrow {5}{4}{ } { }{ }{ } { }{1}{9}
\setrow { }{ }{2} { }{ }{ } {7}{ }{ }
\setrow { }{9}{ } { }{3}{ } { }{8}{ }
\setrow {2}{ }{ } {8}{ }{4} { }{ }{7}
\setrow { }{1}{ } {9}{ }{7} { }{6}{ }
\shownumber{}
\end{scope}
\end{tikzpicture}
\vspace{-2cm}
\begin{tikzpicture}[rotate=25,scale=.5]
\begin{scope}
\filldraw[white] (0, 0) rectangle (9, 9);
\draw (0, 0) grid (9, 9);
\draw[very thick, scale=3] (0, 0) grid (3, 3);
\setcounter{row}{1}
\setrow { }{2}{ } {5}{ }{1} { }{9}{ }
\setrow {8}{ }{ } {2}{ }{3} { }{ }{6}
\setrow { }{3}{ } { }{6}{ } { }{7}{ }
\setrow { }{ }{1} { }{ }{ } {6}{ }{ }
\setrow {5}{4}{ } { }{ }{ } { }{1}{9}
\setrow { }{ }{2} { }{ }{ } {7}{ }{ }
\setrow { }{9}{ } { }{3}{ } { }{8}{ }
\setrow {2}{ }{ } {8}{ }{4} { }{ }{7}
\setrow { }{1}{ } {9}{ }{7} { }{6}{ }
\shownumber{}
\end{scope}
\end{tikzpicture}
\vspace{-9cm}
\hspace{3cm}
\begin{tikzpicture}[rotate=15,scale=.5]
\begin{scope}
\filldraw[white] (0, 0) rectangle (9, 9);
\draw (0, 0) grid (9, 9);
\draw[very thick, scale=3] (0, 0) grid (3, 3);
\setcounter{row}{1}
\setrow { }{2}{ } {5}{ }{1} { }{9}{ }
\setrow {8}{ }{ } {2}{ }{3} { }{ }{6}
\setrow { }{3}{ } { }{6}{ } { }{7}{ }
\setrow { }{ }{1} { }{ }{ } {6}{ }{ }
\setrow {5}{4}{ } { }{ }{ } { }{1}{9}
\setrow { }{ }{2} { }{ }{ } {7}{ }{ }
\setrow { }{9}{ } { }{3}{ } { }{8}{ }
\setrow {2}{ }{ } {8}{ }{4} { }{ }{7}
\setrow { }{1}{ } {9}{ }{7} { }{6}{ }
\shownumber{}
\end{scope}
\end{tikzpicture}
\end{document}
答案2
sudoku
以下是使用包(绘制数独网格)和pgf-blur
tikz 库(添加模糊阴影)的解决方案:
\documentclass[tikz]{standalone}
\usepackage{sudoku}
\setlength\sudokusize{5cm}
\renewcommand*\sudokuformat[1]{\small #1}
\setlength\sudokuthickline{1pt}
\setlength\sudokuthinline{.4pt}
\usetikzlibrary{shadows,shadows.blur,fit,backgrounds}
\tikzset{
sudoku grid/.style={
fill=white,text width=\sudokusize,
draw,inner sep=2mm,blur shadow,
},
every shadow/.style={
shadow opacity=20,
shadow blur steps=20,
shadow blur radius=.5em,
shadow xshift=.5em,
shadow yshift=-.5em,
shadow scale=1,
},
}
\begin{document}
\begin{tikzpicture}
\node[rotate=30,sudoku grid] at (-2,1){%
\begin{sudoku-block}
|2|5| | |3| |9| |1|.
| |1| | | |4| | | |.
|4| |7| | | |2| |8|.
| | |5|2| | | | | |.
| | | | |9|8|1| | |.
| |4| | | |3| | | |.
| | | |3|6| | |7|2|.
| |7| | | | | | |3|.
|9| |3| | | |6| |4|.
\end{sudoku-block}%
};
\node[rotate=-45,sudoku grid] at (3,1){%
\begin{sudoku-block}
| |2| | |3| |9| |7|.
| |1| | | | | | | |.
|4| |7| | | |2| |8|.
| | |5|2| | | |9| |.
| | | |1|8| |7| | |.
| |4| | | |3| | | |.
| | | | |6| | |7|1|.
| |7| | | | | | | |.
|9| |3| |2| |6| |5|.
\end{sudoku-block}
};
\node[sudoku grid] at (0,1){%
\begin{sudoku-block}
|2|5| | |3| |9| |1|.
| |1| | | |4| | | |.
|4| |7| | | |2| |8|.
| | |5|2| | | | | |.
| | | | |9|8|1| | |.
| |4| | | |3| | | |.
| | | |3|6| | |7|2|.
| |7| | | | | | |3|.
|9| |3| | | |6| |4|.
\end{sudoku-block}%
};
\begin{scope}[on background layer]
\node[fit=(current bounding box),inner sep=3mm,fill=white]{};
\end{scope}
\end{tikzpicture}
\end{document}