How do I create a Shidoku grid?
You don't need to modify sudoku.sty
, just to use its infrastructure: we can use the macros as modified by Harish Kumar, but changing their names. In this way you can input both sudoku and shidoku puzzles using a similar syntax.
\documentclass{article}
\usepackage{sudoku}
\makeatletter
\newcommand*\@shidoku@grid{
\linethickness{\sudokuthinline}%
\multiput(0,0)(1,0){5}{\line(0,1){4}}%
\multiput(0,0)(0,1){5}{\line(1,0){4}}
\linethickness{\sudokuthickline}%
\multiput(0,0)(2,0){2}{\line(0,1){4}}%
\multiput(0,0)(0,2){2}{\line(1,0){4}}
\linethickness{0.5\sudokuthickline}%
\put(0,0){\framebox(0,0){}}%
\put(4,0){\framebox(0,0){}}%
\put(0,4){\framebox(4,0){}}%
\put(4,0){\framebox(0,4){}}
}
\newenvironment{shidoku-block}{%
\catcode`\|=\active
\@sudoku@activate
\setcounter{@sudoku@col}{-1}%
\setcounter{@sudoku@row}{3}%
\setlength\unitlength{.111111\sudokusize}%
\begin{picture}(4,4)%
\@shidoku@grid\@shidoku@grab@arguments
}{\end{picture}}
\def\@shidoku@grab@arguments#1.#2.#3.#4.{\scantokens{#1.#2.#3.#4.}}
\newenvironment{shidoku}{%
\begin{center}%
\begin{shidoku-block}}{\end{shidoku-block}\end{center}}
\makeatother
\begin{document}
\begin{shidoku}
|2|5| | |.
| |1| | |.
|4| |7| |.
| | |5|2|.
\end{shidoku}
\begin{sudoku}
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
\end{sudoku}
\end{document}
Here's a possible solution using a tabular
:
\documentclass{article}
\usepackage{array}
\newcolumntype{P}{%
>{\rule[-0.6cm]{0pt}{1.5cm}\centering$}p{1cm}<{$}}
\begin{document}
\noindent\begin{tabular}{!{\vrule width 2pt}P|P!{\vrule width 2pt}P|P!{\vrule width 2pt}}
\noalign{\hrule height 2pt}
a & b & c & d \tabularnewline
\hline
a & b & c & d \tabularnewline
\noalign{\hrule height 2pt}
a & b & c & d \tabularnewline
\hline
a & b & c & d \tabularnewline
\noalign{\hrule height 2pt}
\end{tabular}
\end{document}
And a solution using TikZ:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,matrix}
\begin{document}
\begin{tikzpicture}
% the matrix
\matrix [matrix of math nodes, nodes in empty cells,
nodes={align=center},
text width=1cm,text depth=0.4cm,text height=0.6cm]
(shi)
{
a & b & c & d \\
a & b & c & d \\
a & b & c & d \\
a & b & c & d \\
};
% vertical rules
\foreach \i in {1,3}
\draw (shi-1-\i.north east) -- (shi-4-\i.south east);
\foreach \i in {1,3}
\draw[line width=2pt] (shi-1-\i.north west) -- (shi-4-\i.south west);
\draw[line width=2pt] (shi-1-4.north east) -- (shi-4-4.south east);
% horizontal rules
\foreach \i in {2,4}
\draw (shi-\i-1.north west) -- (shi-\i-4.north east);
\foreach \i in {2,4}
\draw[line width=2pt] (shi-\i-1.south west) -- (shi-\i-4.south east);
\draw[line width=2pt] (shi-1-1.north west) -- (shi-1-4.north east);
\end{tikzpicture}
\end{document}
And here's my first approach using a simpe tabular
but now I've added the necessary font adjustments and defined an environment to simplify the writing; now a Shidoku is produce simply by something like:
\begin{shidoku}
\Srow{2}{5}{}{}
\Srow{}{1}{}{}
\Srow{4}{}{7}{}
\Srow{}{}{5}{2}
\end{shidoku}
Here's the code:
\documentclass{article}
\usepackage{sudoku}
\usepackage{array}
\newcolumntype{P}{%
>{\rule[-6pt]{0pt}{30pt}\centering\Huge\sffamily}p{19pt}}
\newcommand\TPLine{\noalign{\hrule height 2pt}}
\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}
\begin{shidoku}
\Srow{2}{5}{}{}
\Srow{}{1}{}{}
\Srow{4}{}{7}{}
\Srow{}{}{5}{2}
\end{shidoku}
\begin{sudoku}
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
| | | | | | | | | |.
\end{sudoku}
\end{document}
I have modified the sudoku.sty
for you and here are the contents of the 4x4 sudoku44.sty
file. Save the contents below in the name sudoku44.sty
and keep it in the same directory as your .tex
file. (Alternatively put the file in C:\Program Files\MiKTeX 2.9\tex\latex\sudoku\
and run a refresh file name data base
if on windows.)
%%
%% This is file `sudoku44.sty'.
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{sudoku}
[2006/03/25 v1.0.1 Sudoku grid]
\newcounter{@sudoku@row}
\newcounter{@sudoku@col}
\newcommand*\@sudoku@separator[1]{%
\stepcounter{@sudoku@col}%
\ifx#1\@sudoku@separator
\expandafter#1%
\else
\ifx.#1%
\setcounter{@sudoku@col}{-1}%
\addtocounter{@sudoku@row}{-1}%
\else
\put(\value{@sudoku@col},\value{@sudoku@row})%
{\makebox(1,1){\sudokuformat{#1}}}%
\fi
\fi
}
\begingroup
\catcode`\|=\active
\gdef\@sudoku@activate{\let|=\@sudoku@separator}
\endgroup
\newcommand*\@sudoku@grid{
\linethickness{\sudokuthinline}%
\multiput(0,0)(1,0){5}{\line(0,1){4}}%
\multiput(0,0)(0,1){5}{\line(1,0){4}}
\linethickness{\sudokuthickline}%
\multiput(0,0)(2,0){2}{\line(0,1){4}}%
\multiput(0,0)(0,2){2}{\line(1,0){4}}
\linethickness{0.5\sudokuthickline}%
\put(0,0){\framebox(0,0){}}%
\put(4,0){\framebox(0,0){}}%
\put(0,4){\framebox(4,0){}}%
\put(4,0){\framebox(0,4){}}
}
\newcommand*\sudokuformat[1]{\Huge\sffamily#1}
\newdimen\sudokusize
\setlength\sudokusize{10cm}
\newdimen\sudokuthinline
\setlength\sudokuthinline{0.4pt}
\newdimen\sudokuthickline
\setlength\sudokuthickline{2pt}
\newenvironment{sudoku-block}{%
\catcode`\|=\active
\@sudoku@activate
\setcounter{@sudoku@col}{-1}%
\setcounter{@sudoku@row}{3}%
\setlength\unitlength{.111111\sudokusize}%
\begin{picture}(4,4)%
\@sudoku@grid\@sudoku@grab@arguments
}{\end{picture}}
\begingroup
\@ifundefined{eTeXversion}{\endgroup
\def\@sudoku@grab@arguments#1{%
\ifx#1\@sudoku@separator
\expandafter#1%
\else
\PackageError{sudoku}{%
Sudoku puzzles are not allowed in the arguments\MessageBreak
of other commands}{%
Either fix this in your source (possibly using the `lrbox'
environment) or use an eTeX based LaTeX format}
\fi
}%
}{\endgroup
\def\@sudoku@grab@arguments#1.#2.#3.#4.{%
\scantokens{#1.#2.#3.#4.}}%
}
\newenvironment{sudoku}{%
\begin{center}%
\begin{sudoku-block}}{\end{sudoku-block}\end{center}}
\endinput
%%
%% End of file `sudoku44.sty'.
Now your main .tex
file (say mysudoku.tex) will be like this:
%-------------sudoku--------------------------------
\documentclass{article}
\usepackage{sudoku44}
%---------------------------------------------------
\begin{document}
\begin{sudoku}
|2|5| | |.
| |1| | |.
|4| |7| |.
| | |5|2|.
\end{sudoku}
%---------------------------------------------------
\end{document}
%---------------------------------------------------
After compiling (with pdflatex, my preference), we get
NOTE: Do not erase or modify the original sudoku.sty
file. Save the new file with a name sudoku44.sty
. Then you can use both the files like
\usepackage{sudoku}
or
\usepackage{sudoku44}
But you can not use both the packages in the same mysudoku.tex
file as they clash.