0

I need to typeset Sudoku tables in LaTeX, and so far I have been able to do most of what I need to do using the logicpuzzle package. One of the few missing things is the ability to write hints inside cells, listing all the possible numbers which could go inside that cell.

Looking at the package documentation, I don't see an option to do this using the package alone, so I wonder if I should use a different package altogether, or if there is a way to extend logicpuzzle to make it display this instead.

So far, this is what I have:

\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{logicpuzzle}

\begin{document}

\tableofcontents
\newpage

\chapter{Sudoku 1}

\begin{logicpuzzle}[rows=9,columns=9,color=orange!50,scale=1.5]
\framepuzzle
\framearea{black}{(1,7)--(4,7)--(4,10)--(1,10)}
\framearea{black}{(4,7)--(7,7)--(7,10)--(4,10)}
\framearea{black}{(7,7)--(10,7)--(10,10)--(7,10)}
\framearea{black}{(1,4)--(4,4)--(4,7)--(1,7)}
\framearea{black}{(4,4)--(7,4)--(7,7)--(7,4)}
\framearea{black}{(7,4)--(10,4)--(10,7)--(10,7)}
\framearea{black}{(1,1)--(1,4)--(4,4)--(4,1)}
\framearea{black}{(4,1)--(7,1)--(7,4)--(4,4)}
\setrow{9}{{},{},{3},{4},{},{5},{6},{},{}}
\setrow{8}{{7},{},{},{},{},{},{},{},{}}
\setrow{7}{{8},{},{},{},{},{},{},{},{}}
\setrow{6}{{9},{},{},{},{},{},{},{},{7}}
\setrow{5}{{},{},{},{},{},{},{},{},{8}}
\setrow{4}{{},{},{},{},{},{},{},{},{9}}
\setrow{3}{{},{},{},{},{},{},{},{},{}}
\setrow{2}{{},{},{},{},{},{},{},{},{}}
\setrow{1}{{},{},{},{},{},{},{},{},{}}
\fillcell{1}{9}
\fillcell{9}{9}
\end{logicpuzzle}

\end{document}

This is the resulting Sudoku:

enter image description here

Is there any way to typeset number hints inside a Sudoku cell using the logicpuzzle package?

Ideally, they would look similar to the answer to this question:

enter image description here

user1301428
  • 1,041
  • Hmm, why don't you use TikZ for this thing? –  Mar 29 '19 at 14:36
  • Also, how do you want the hint to look like? –  Mar 29 '19 at 14:37
  • @JouleV I have no preference as to what the hint would look like at this point, I was mostly curious to see if this was even possible. Ideally, I would break up the cell in 9 parts, and enter the hint in the relevant subcell, so to say – user1301428 Mar 29 '19 at 14:42
  • @JouleV I suppose I could use TikZ, but I found this package which looked perfect for what I need to do. Well, except for the hints :P – user1301428 Mar 29 '19 at 14:42
  • It is always possible (but I don't know if it is possible with your package). Please show how the hints should look like. –  Mar 29 '19 at 14:48
  • @JouleV Gotcha! I have updated my question with a screenshot and a link to another question on this site. I don't need any highlights in the hint, or anything special, just the numbers with that format would already be great. – user1301428 Mar 29 '19 at 14:58

1 Answers1

2

I define some simple macros for that.

\documentclass[tikz]{standalone}
\newcommand\inserthint[3]{%
    \foreach \i in {#3} {
        \ifnum\i<4
            \draw ({(#1-0.5)+(\i*0.25)},#2+0.25) node[font=\scriptsize] {\i};
        \else
            \ifnum\i>6
                \draw ({(#1-2)+(\i*0.25)},#2-0.25) node[font=\scriptsize] {\i};
            \else
                \draw ({(#1-1.25)+(\i*0.25)},#2) node[font=\scriptsize] {\i};
            \fi
        \fi
    }
}
\begin{document}
\begin{tikzpicture}
\draw[very thick,step=3] (0,0) grid (9,9);
\draw (0,0) grid (9,9);
\begin{scope}[every node/.style={minimum size=1cm},xshift=-.5cm,yshift=-.5cm]
\renewcommand{\arraystretch}{1}
\node at (1,6) {9};
\node at (1,7) {8};
\node at (1,8) {7};
\node at (3,9) {3};
\node at (4,9) {4};
\node at (6,9) {5};
\node at (7,9) {6};
\node at (9,6) {7};
\node at (9,5) {8};
\node at (9,4) {9};
\end{scope}
\begin{scope}[xshift=-.5cm,yshift=-.5cm]
\inserthint{1}{9}{1,...,9}
\inserthint{4}{6}{2,5,6,3,7}
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here


In case you need to fill, we should rearrange the code a bit. As for the "normal" nodes, you only have to add option fill=.... As for the "hint" nodes, I added an argument to the macro.

\documentclass[tikz]{standalone}
\newcommand\inserthint[4]{%
    \fill[#4] (#1-.5,#2-.5) rectangle (#1+.5,#2+.5);
    \foreach \i in {#3} {
        \ifnum\i<4
            \draw ({(#1-0.5)+(\i*0.25)},#2+0.25) node[font=\scriptsize] {\i};
        \else
            \ifnum\i>6
                \draw ({(#1-2)+(\i*0.25)},#2-0.25) node[font=\scriptsize] {\i};
            \else
                \draw ({(#1-1.25)+(\i*0.25)},#2) node[font=\scriptsize] {\i};
            \fi
        \fi
    }
}
\begin{document}
\begin{tikzpicture}
\begin{scope}[every node/.style={minimum size=1cm},xshift=-.5cm,yshift=-.5cm]
\renewcommand{\arraystretch}{1}
\node at (1,6) {9};
\node at (1,7) {8};
\node at (1,8) {7};
\node at (3,9) {3};
\node at (4,9) {4};
\node at (6,9) {5};
\node at (7,9) {6};
\node at (9,6) {7};
\node at (9,5) {8};
\node[fill=blue!30] at (9,4) {9};
\node[fill=red!30] at (2,3) {};
\end{scope}
\begin{scope}[xshift=-.5cm,yshift=-.5cm]
\inserthint{1}{9}{1,...,9}{yellow}
\inserthint{4}{6}{2,5,6,3,7}{green!50}
\end{scope}
\draw[very thick,step=3] (0,0) grid (9,9);
\draw (0,0) grid (9,9);
\end{tikzpicture}
\end{document}

enter image description here