0

Can you please help me to get the following style in the below image by using the code: \answergrid :

enter image description here

Thanks!

ChB
  • 1
  • Welcome! What have you tried so far? What's the context? Please provide a minimal example (code) showing what you've tried / what the problem is. Also, do you just want to reproduce that picture as is? If so, why not just include it or draw it in another programme and include it? – cfr May 12 '16 at 20:36
  • You have not provided us any information about where this macro, \answergrid, comes from. Perhaps you meant the version from this answer: http://tex.stackexchange.com/questions/285074/mcq-answer-grid-with-tikz/285086#285086 – Steven B. Segletes May 12 '16 at 20:37
  • Do you mean something like http://tex.stackexchange.com/a/285086/46716 and http://tex.stackexchange.com/a/285952/46716? – Maarten Dhondt May 12 '16 at 20:37
  • This may be related: http://tex.stackexchange.com/questions/219425/how-to-generate-a-dynamic-bubble-answer-sheet-for-multiple-choice-exam – Steven B. Segletes May 12 '16 at 20:39

1 Answers1

1

This is an adaptation of the code from https://tex.stackexchange.com/a/285086/46716

\documentclass{article}
\usepackage{tikz}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\answergrid}{ O{1} m m m }{
    \begin{tikzpicture}[box/.style={draw,minimum~width=7mm,minimum~height=4mm},y=.5cm]
        \seq_set_split:Nnn \l_tmpa_seq{;}{#4}
        \int_step_inline:nnnn {#1} {1} {#1+#2-1} {
            \node[box] at (##1+1-#1,#3+.5) {##1};
            \int_step_inline:nnnn {1} {1} {#3} {
                \int_compare:nNnTF {####1} = {\seq_item:Nn \l_tmpa_seq {##1-#1+1}} {
                    \node[box,fill=green] at (##1+1-#1, #3-####1) {\int_to_Alph:n{####1}};
                }{
                    \node[box] at (##1+1-#1, #3-####1) {\int_to_Alph:n{####1}};
                }
            }
        }
    \end{tikzpicture}
}
\ExplSyntaxOff

\begin{document}

    \sffamily\small

    \answergrid      {10} {4} {1;2;4;3;2;3;1;2;3;4}

    \vspace*{1cm}

    \answergrid [11] {10} {4} {1;2;4;3;2;3;1;2;1;2}

\end{document}

enter image description here

  • @egreg I changed the sequence variable to the scratch one. Could you ellaborate on why the \seq_new:N is needed? I don't know that much about LaTeX3 and it seemed to work fine without it. – Maarten Dhondt May 14 '16 at 10:08