2

I used this instruction by Herbert to prepare my own answer-sheet. However, I have one problem with a numeration of the second and third column. I want to have the second and third column numbered continuously?

\documentclass[11pt]{article}
\usepackage{geometry}
\usepackage{polski}
\usepackage[utf8]{inputenc}
\newgeometry{tmargin=1.5cm, bmargin=1cm, lmargin=1.5cm, rmargin=1.5cm}
\usepackage{multicol}

\usepackage{array}
\pagestyle{empty}
\parindent=0pt
\baselineskip=6.35mm
\parskip=0pt
\makeatletter
\newcommand*{\InitToks}{\toks@={}}
\newcommand{\AddToks}[1]{\toks@=\expandafter{\the\toks@ #1}}
\newcommand*{\PrintToks}{\the\toks@}
\unitlength=1mm
\def\BOX{\framebox(3.55,2){}}
\newcount\rowNo
\newcommand*{\dynTable}[1]{%
\begingroup
\InitToks
\AddToks{\tabcolsep=0pt\begin{tabular}{c*{11}{>{\centering}p{6.35mm}}}}%
\AddToks{&&A&B&C&D&E&\tabularnewline}
\rowNo=0 %
\loop\ifnum\rowNo<#1\relax
\advance\rowNo by 1
\AddToks{\strobe & }
\expandafter\AddToks\expandafter{%
 \the\rowNo & 
 \BOX & \BOX & \BOX & \BOX & \BOX   %
\tabularnewline}%
\repeat
\AddToks{\end{tabular}}%
\PrintToks
\endgroup}
\makeatother
\def\strobe{\rule{0pt}{4mm}\rule{3mm}{2.54mm}}

\begin{document}
\sffamily\small
{\large\begin{center}KARTA ODPOWIEDZI\end{center}}
Imię i nazwisko: \line(2,0){89} 
\bigskip
 \begin{multicols}{3}

 \dynTable{40} %  column 1
 \dynTable{40} %  column 2
 \dynTable{40} %  column 3

 \end{multicols}
 \end{document}

enter image description here

1

Use an auxiliary counter, say numberofquestions which is increased each time the row counter is increased, but not reset with a new column.

Since there is token expansion involved, it's necessary to write the number explicitly as \number\value{numberofquestions} instead of \thenumberofquestions (which replaced \the\rowNo in this code.

After a new page, one should say \setcounter{numberofquestions}{0} perhaps, unless the counting should be continued of course.

\documentclass[11pt]{article}
\usepackage{geometry}
\usepackage{polski}
\usepackage[utf8]{inputenc}
\newgeometry{tmargin=1.5cm, bmargin=1cm, lmargin=1.5cm, rmargin=1.5cm}
\usepackage{multicol}

\usepackage{array}
\pagestyle{empty}
\parindent=0pt
\baselineskip=6.35mm
\parskip=0pt
\makeatletter
\newcommand*{\InitToks}{\toks@={}}
\newcommand{\AddToks}[1]{\toks@=\expandafter{\the\toks@ #1}}
\newcommand*{\PrintToks}{\the\toks@}
\unitlength=1mm
\def\BOX{\framebox(3.55,2){}}
\newcount\rowNo
\newcounter{numberofquestions}
\newcommand*{\dynTable}[1]{%
\begingroup
\InitToks
\AddToks{\tabcolsep=0pt\begin{tabular}{c*{11}{>{\centering}p{6.35mm}}}}%
\AddToks{&&A&B&C&D&E&\tabularnewline}
\rowNo=0 %
\loop\ifnum\rowNo<#1\relax
\advance\rowNo by 1
\stepcounter{numberofquestions}
\AddToks{\strobe & }
\expandafter\AddToks\expandafter{%
 \number\value{numberofquestions} & 
 \BOX & \BOX & \BOX & \BOX & \BOX   %
\tabularnewline}%
\repeat
\AddToks{\end{tabular}}%
\PrintToks
\endgroup}
\makeatother
\def\strobe{\rule{0pt}{4mm}\rule{3mm}{2.54mm}}

\begin{document}
\sffamily\small
{\large\begin{center}KARTA ODPOWIEDZI\end{center}}
Imię i nazwisko: \line(2,0){89} 
\bigskip
 \begin{multicols}{3}

 \dynTable{40} %  column 1
 \dynTable{40} %  column 2
 \dynTable{40} %  column 3

 \end{multicols}
 \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