newcommand 多项选择考试

newcommand 多项选择考试

我必须进行几次多项选择测试,为了让我的生活更轻松,我定义了这个新命令

\newcommand{\preg}[6]{
\question {#1}
\begin{choices}
\choice \({#2}\)
\choice \({#3}\)
\choice \({#4}\)
\choice \({#5}\)
\choice \({#6}\)
\end{choices}}

但是当我在里面使用它时,它questions不起作用。我这样使用它

\begin{multicols}
\begin{questions}
\preg{Factoriza el siguiente polinomio:\(an+6a+n+6\),
(n+6)(a+1),
(n+1)(a-6),
(n-a)(6+1),
(n-6)(a-1),
(n-1)(a+6)}
\end{questions}

错误如下:

! Argument of \end has an extra }.
<inserted text>
\par
l.29 \end{document}
I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.
Runaway argument?
! Paragraph ended before \end was complete.
<to be read again>
\par
l.29 \end{document}
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
! Argument of \end has an extra }.
<inserted text>
\par
l.29 \end{document}
I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.
Runaway argument?
! Paragraph ended before \end was complete.
<to be read again>
\par
l.29 \end{document}
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
)
! Emergency stop.

我知道错误出在命令中,因为当我不使用它时,一切都正常。我该如何修复它?

答案1

您的代码存在一些问题。

  1. 每个参数都newcommand必须写在括号中{...}
  2. multicols需要一个额外的参数来指定你想要的列数

我添加了一个可以运行的 MWE,其中有一些我相信您正在使用的包。

\documentclass{exam}

\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{multicol}

\newcommand{\preg}[6]{
\question {#1}
\begin{choices}
\choice \({#2}\)
\choice \({#3}\)
\choice \({#4}\)
\choice \({#5}\)
\choice \({#6}\)
\end{choices}}

\begin{document}
\begin{multicols}{2}%two columns
\begin{questions}
\preg{Factoriza el siguiente polinomio:\(an+6a+n+6\),}%
     {(n+6)(a+1),}{(n+1)(a-6),}{(n-a)(6+1),}{(n-6)(a-1),}{(n-1)(a+6)}
\end{questions}
\end{multicols}
\end{document}

相关内容