1

I would like to create the following table in LaTeX:

\begin{table}[h]\centering
        \begin{tabular}{|c|c|c|}\hline
        Problem & Score & Max \\ \hline
        5B       &       &     \\ \hline
        5I       &       &     \\ \hline
        5J       &       &     \\ \hline
        5K       &       &     \\ \hline
        5L       &       &     \\ \hline
        Total   &       &     \\ \hline
        \end{tabular}
\end{table}

In this example, I have the assigned problems 5B, 5I, etc, but I would like to create a command that takes in a variable number of questions as arguments, i.e. something like

\tableofproblems{5B,5I,5J,5K,5L}

or

\tableofproblems{5B}{5I}{5J}{5K}{5L}

preferably the first one. Is this possible? I would like to be able to call this command to create tables with 2 problems, 7 problems, etc.

1 Answer 1

1
\documentclass{article}
\usepackage{array}

\ExplSyntaxOn
\NewDocumentCommand \tableofproblems { m }
  {
    \begin{tabular}{|c|c|c|}\hline
    Problem & Score & Max \\ \hline
    \clist_map_inline:nn { #1 } 
      { ##1 & & \\ \hline }
    Total &  & \\ \hline
    \end{tabular}
  }
\ExplSyntaxOff

\begin{document}

\tableofproblems{5B,5I,5J,5K,SL}

\end{document}

Output of the above code

1
  • This is great! Thanks!
    – btshepard
    Sep 30, 2021 at 5:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .