5

I have the following code for creating a 4 x 4 Sudoku puzzle. But the problem with this code is that the Sudoku board that it generates is too big. I'm looking to generate a much smaller, perhaps one-half or three-fourth the size of what this code currently gives me, Sudoku board that I can populate. I heard that one can do this using the Tikz package, but after playing around with it all day, I got no where.

One other thing that I would like to do after being able to generate smaller 4 x 4 Sudoku boards is to be able to situate 2 or more such Sudoku boards side by side. So any help is greatly appreciated! As a side note, I am using ShareLatex.com to write a report.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{array}

\newcolumntype{P}{%
\rule[-6pt]{0pt}{30pt}\centering\Huge\sffamily}p{19pt}

\newcommand\TPLine{\noalign{\hrule height 1pt}}

\newcounter{shrow}
\newenvironment{shidoku}
  {\setcounter{shrow}{0}\begin{center}\begin{tabular}{!{\vrule width 2pt}P|P!{\vrule width 2pt}P|P!{\vrule width 2pt}}}
  {\end{tabular}\end{center}}

\newcommand\Srow[4]{%
  \ifnum\value{shrow}=0 \TPLine\fi\stepcounter{shrow}%
  #1 & #2 & #3 & #4\tabularnewline
  \ifnum\value{shrow}=2 \TPLine\else\ifnum\value{shrow}=4 \TPLine\else\hline\fi\fi}

\begin{document}
\frame{\titlepage}
\begin{frame}

\begin{shidoku}
\Srow{1}{2}{3}{4}
\Srow{3}{4}{1}{2}
\Srow{4}{3}{2}{1}
\Srow{2}{1}{4}{3}
\end{shidoku}

\end{frame}
\end{document}
  • Not sure if it's just me, but your code does not compile. – Alenanno Dec 14 '15 at 8:18
6

You can use logicpuzzle package for this task. It provides some well known puzzles environments, but you can create your own environments like a 4x4 sudoku:

\documentclass{beamer}
\usepackage{logicpuzzle}

\newenvironment{shidoku}[1][]{%
\begin{logicpuzzle}[rows=4,columns=4,#1]
\begin{puzzleforeground}
\framepuzzle
\framearea{black}{(1,1)--(3,1)--(3,3)--(1,3)--cycle}
\framearea{black}{(3,3)--(3,5)--(5,5)--(5,3)--cycle}
\end{puzzleforeground}
}{\end{logicpuzzle}}

\begin{document}
\begin{frame}
\begin{shidoku}
\setrow{1}{1,2,3,4}
\setrow{2}{3,4,1,2}
\setrow{3}{4,3,2,1}
\setrow{4}{2,1,4,3}
\end{shidoku}
%
\begin{shidoku}[scale=.5, fontsize=scriptsize]
\setrow{1}{1,2,3,4}
\setrow{2}{3,4,1,2}
\setrow{3}{4,3,2,1}
\setrow{4}{2,1,4,3}
\end{shidoku}
\end{frame}
\end{document}

![enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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