我不是 TeX 的专家用户。我想根据自己的需要对下面的代码进行一些小改动。选项是
\choise0 for wrong answer and
\choice1 for the correct answer
我该怎么做
\choise for wrong answer and
\correctchoice for the correct answer
我也想在最后显示答案。感谢您的所有帮助和时间。
\documentclass{article}
\usepackage{environ}
\newlength{\choiceslen}
\newif\ifshowcorrect
\newcounter{choices}
\newcommand{\choicefinal}[1]{%
\ifnum\value{choices}>0 \hfill\fi\egroup
\hspace{0pt}%
\hbox to\choiceslen
\bgroup
\stepcounter{choices}%
\ifcase#1\relax
(\Alph{choices})%
\else
\ifshowcorrect
\expandafter\underline
\fi
{(\Alph{choices})}%
\fi\space}
\newcommand{\choicetemp}[1]{\stepcounter{choices}\space(\Alph{choices})\cr}
\NewEnviron{choices}
{\setcounter{choices}{0}%
\let\choice\choicetemp
\settowidth{\choiceslen}{\vbox{\halign{##\hfil\cr\BODY\crcr}}}
\ifdim\choiceslen>.5\textwidth
\setlength{\choiceslen}{\textwidth}%
\else
\ifdim\choiceslen>.25\textwidth
\setlength{\choiceslen}{.5\textwidth}%
\else
\setlength{\choiceslen}{.25\textwidth}%
\fi
\fi
\let\choice\choicefinal
\setcounter{choices}{0}%
\begin{flushleft}
\bgroup\BODY\hfill\egroup
\end{flushleft}}
\begin{document}
\showcorrecttrue
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orange
\choice0 pear
\end{choices}
\begin{choices}
\choice0 apple
\choice0 banana
\choice0 orange
\choice1 pear
\end{choices}
%\showcorrecttrue
\begin{choices}
\choice0 apple
\choice0 banana
\choice1 orange, eeeeeeeee, eeeeeeeee, eeeeeeeee
\choice0 pear
\end{choices}
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orang, eeeeeeeee
\choice0 pear
\end{choices}
\begin{choices}
\choice0
\begin{minipage}[t]{\textwidth}
This is a very long question. This is a very long question. This is a very long question. This is a very long question. This is a very long question. This is a very long question.
\end{minipage}
\choice0
\begin{minipage}[t]{\textwidth}
This is a very long question. This is a very long question. This is a very long question. This is a very long question. This is a very long question. This is a very long question.
\end{minipage}
\choice0
\begin{minipage}[t]{\textwidth}
This is a very long question. This is a very long question. This is a very long question. This is a very long question. This is a very long question. This is a very long question.
\end{minipage}
\choice0
\begin{minipage}[t]{\textwidth}
This is a very long question. This is a very long question. This is a very long question. This is a very long question. This is a very long question. This is a very long question.
\end{minipage}
\end{choices}
\end{document}
答案1
下面我定义\shorthandchoice
更新\choice
默认为\choice{0}
和\correctchoice
为\choice{1}
:
\documentclass{article}
\usepackage{environ}
\newlength{\choiceslen}
\newif\ifshowcorrect
\newcounter{choices}
\newcommand{\choicefinal}[1]{%
\ifnum\value{choices}>0 \hfill\fi\egroup
\hspace{0pt}%
\hbox to\choiceslen
\bgroup
\stepcounter{choices}%
\ifcase#1\relax
(\Alph{choices})%
\else
\ifshowcorrect
\expandafter\underline
\fi
{(\Alph{choices})}%
\fi\space
}
\newcommand{\choicetemp}[1]{%
\stepcounter{choices}%
\space(\Alph{choices})\cr
}
\NewEnviron{choices}{%
\setcounter{choices}{0}%
\let\choice\choicetemp
\shorthandchoice% <---------- Add \choice shorthand
\settowidth{\choiceslen}{\vbox{\halign{##\hfil\cr\BODY\crcr}}}
\ifdim\choiceslen>.5\textwidth
\setlength{\choiceslen}{\textwidth}%
\else
\ifdim\choiceslen>.25\textwidth
\setlength{\choiceslen}{.5\textwidth}%
\else
\setlength{\choiceslen}{.25\textwidth}%
\fi
\fi
\let\choice\choicefinal
\shorthandchoice% <---------- Add \choice shorthand
\setcounter{choices}{0}%
\begin{flushleft}
\bgroup\BODY\hfill\egroup
\end{flushleft}
}
\newcommand{\shorthandchoice}{%
\let\oldchoice\choice
\renewcommand{\choice}{\oldchoice{0}}
\def\correctchoice{\oldchoice{1}}
}
\begin{document}
\showcorrecttrue
\begin{choices}
\choice apple
\correctchoice banana
\choice orange
\choice pear
\end{choices}
\begin{choices}
\choice apple
\choice banana
\choice orange
\correctchoice pear
\end{choices}
%\showcorrecttrue
\begin{choices}
\choice apple
\choice banana
\correctchoice orange, eeeeeeeee, eeeeeeeee, eeeeeeeee
\choice pear
\end{choices}
\begin{choices}
\choice apple
\correctchoice banana
\choice orang, eeeeeeeee
\choice pear
\end{choices}
\begin{choices}
\choice
\begin{minipage}[t]{\textwidth}
This is a very long question. This is a very long question. This is a very long question.
This is a very long question. This is a very long question. This is a very long question.
\end{minipage}
\choice
\begin{minipage}[t]{\textwidth}
This is a very long question. This is a very long question. This is a very long question.
This is a very long question. This is a very long question. This is a very long question.
\end{minipage}
\choice
\begin{minipage}[t]{\textwidth}
This is a very long question. This is a very long question. This is a very long question.
This is a very long question. This is a very long question. This is a very long question.
\end{minipage}
\choice
\begin{minipage}[t]{\textwidth}
This is a very long question. This is a very long question. This is a very long question.
This is a very long question. This is a very long question. This is a very long question.
\end{minipage}
\end{choices}
\end{document}