2

I found the following nice code in this question Mcq Answer Grid with Tikz but I want to add name box on an answergrid

Here is the code :

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

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

       \begin{document}

\sffamily\small

\answergrid      {20} {4} {0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0}
\answergrid [21] {20} {4} {0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0}

 \end{document}

Here is the Ouput

enter image description here

Mensch
  • 65,388
haithem
  • 1,155

1 Answers1

1

You can do it with simply adding the following line (change the used values to your needs):

\hfill Name: \hspace{2cm}\vspace{1cm}

With the complete code

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

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


\begin{document}

\sffamily\small

\hfill Name: \hspace{2cm}\vspace{1cm} % <===============================

\answergrid      {20} {4} {0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0}
\answergrid [21] {20} {4} {0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0}

\end{document}

you get the result:

enter image description here

Mensch
  • 65,388