Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to imitate the first page of this pdf by using the following code for the hard job of making the sudoku grids.

Indeed the problem is just to superpose several sudoku grids, and not to draw this sudoku grids individually.

CODE

\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}
share|improve this question

2 Answers 2

up vote 6 down vote accepted

How about something like the code below? I only reuse your nice tikzpicture, make a white background, use the rotate option and superpose with hspace and vspace the pictures.

The output is as here: Output of code

If this helps you, I am sure you can adapt this trick to make the whole picture as you want.

Code:

\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}
share|improve this answer
    
There is only one small problem with the numbers of rows and columns but I do not really want to use them. –  projetmbc Jan 31 '13 at 18:16
1  
Delete \shownumber commands. You might also want to rotate the numbers in the grid: add transform shape to the nodes: \node[digit,name={\arabic{row}-\arabic{col}},transform shape] at (\x, \y) {\n}; –  Sašo Živanović Jan 31 '13 at 19:49

Here is a solution using sudoku package (to draw sudoku grid) and pgf-blur tikz library (to add a blurred shadow):

enter image description here

\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}
share|improve this answer
    
Thanks for the blur option. –  projetmbc Jan 31 '13 at 22:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.