I want to make macros for drawing group of questions with same answers with customizable text, number of answers and design (column widths, alignment, etc.), like this:
\begin{questionGroup}{Question group description}{3}{|p{100}|c|c|c|}
Questions& yes& no& maybe\\\hline
\groupQuestion{Question1}
\groupQuestion{Question2}
\end{questionGroup}
The number of columns in generated rows is dynamical and numbers in all cells except first are also generated.
The best I had managed to make work is:
\documentclass{article}
\usepackage{tikz}
% #1 - question group title
% #2 - answer count
% #3 - table design
\newenvironment{questionGroup}[3]{
\noindent\QuestionID{}\textbf{#1}\\
\setlength{\tabcolsep}{2pt}
\setcounter{subQuestionID}{0}
\newcounter{answerCount}
\setcounter{answerCount}{#2}
\begin{tabular}{#3}
\hline
}{\end{tabular}\\}
\newcommand{\groupQuestion}[1]{
\subQuestionID{}.~#1&
\foreach \n in {1,...,\value{answerCount}}{
\n
}
\\\hline
}
\newcounter{QuestionID}
\newcommand{\QuestionID}{\addtocounter{QuestionID}{1}\textit{\arabic{QuestionID}.}}
\newcounter{subQuestionID}
\newcommand{\subQuestionID}{\addtocounter{subQuestionID}{1}{\textit{\alph{subQuestionID}}}}
\begin{document}
\begin{questionGroup}{Question group description}{3}{|p{100}|c|c|c|}
Questions& yes& no& maybe\\\hline
\groupQuestion{Question1}
\groupQuestion{Question2}
\end{questionGroup}
\end{document}
To complete this I need the following:
- [DONE]
pass a number of answers (parameter of the environment) inside\groupQuestion{}
command; - [DONE]
print incrementing numbers for each answer of each question in separate column from 1 to number given as environment parameter; - output table column separators from
\foreach
- currently it returns error after inserting&
before\n