这个问题导致了一个新的方案的出现:
multiple-choice
我们可以有三种类型的列排版。参见下图:
上面的图像是使用以下 LaTeX 代码创建的:
\documentclass{article}
\usepackage{ifthen}
\usepackage{calc}
\setlength\parindent{0pt}
%usage \choice{ }{ }{ }{ }
%(A)(B)(C)(D)
\newcommand{\fourch}[4]{
\par
\begin{tabular}{*{4}{@{}p{0.23\textwidth}}}
(A)~#1 & (B)~#2 & (C)~#3 & (D)~#4
\end{tabular}
}
%(A)(B)
%(C)(D)
\newcommand{\twoch}[4]{
\par
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
(A)~#1 & (B)~#2
\end{tabular}
\par
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
(C)~#3 & (D)~#4
\end{tabular}
}
%(A)
%(B)
%(C)
%(D)
\newcommand{\onech}[4]{
\par
(A)~#1 \par (B)~#2 \par (C)~#3 \par (D)~#4
}
\newlength\widthcha
\newlength\widthchb
\newlength\widthchc
\newlength\widthchd
\newlength\widthch
\newlength\tabmaxwidth
\setlength\tabmaxwidth{0.96\textwidth}
\newlength\fourthtabwidth
\setlength\fourthtabwidth{0.25\textwidth}
\newlength\halftabwidth
\setlength\halftabwidth{0.5\textwidth}
\newcommand{\choice}[4]{
\settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}
\settowidth\widthchb{BM.#2}
\ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}
\settowidth\widthchb{CM.#3}
\ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}
\settowidth\widthchb{DM.#4}
\ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}
\ifthenelse{\widthch<\fourthtabwidth}{\fourch{#1}{#2}{#3}{#4}}
{\ifthenelse{\widthch<\halftabwidth\and\widthch>\fourthtabwidth}{\twoch{#1}{#2}{#3}{#4}}
{\onech{#1}{#2}{#3}{#4}}}
}
\begin{document}
Question:
\choice{apple}{banana}{orange}{pear}
\par
Another Question:
\choice{apple}{banana}{orang, eeeeeeeee}{pear}
\par
Third Question:
\choice{apple}{banana}{orange, eeeeeeeee, eeeeeeeee, eeeeeeeee}{pear}
\end{document}
然后主算法检查选项的最长宽度,如果大于0.5\textwidth
,则应使用单列样式。如果最大选项大于0.25\textwidth
,则可将其放在双列样式中。否则,所有选项可以放在一行上。
但我对上面的代码并不满意。我想使用如下代码片段:
\begin{question}
What do you like best?
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orange
\choice0 pear
\end{choices}
\end{question}
==>
What do you like best?..................................(B)
A. apple B. banana C. orange D. pear
\begin{question}
What do you like best?
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orang, eeeeeeeee
\choice0 pear
\end{choices}
\end{question}
==>
What do you like best?..................................(B)
A. apple B. banana
C. orange, eeeeeeeee D. pear
\begin{question}
What do you like best?
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orange, eeeeeeeee, eeeeeeeee, eeeeeeeee
\choice0 pear
\end{choices}
\end{question}
==>
What do you like best?..................................(B)
A. apple
B. banana
C. orange, orange, eeeeeeeee, eeeeeeeee, eeeeeeeee
D. pear
在此代码中,使用环境而不是新命令。一个问题是答案可以自动放在问题行的末尾。最好有答案“显示/隐藏”选项。
附录:我想到了一个通用的方法,即:当 LaTeX 解析器看到 或\choice0
时\choice1
,它可以将后面的文本放在一个标记列表中,然后在离开问题或选择环境时,所有四个标记列表将根据它们的长度进行排版,但抱歉我不熟悉 LaTeX 编程。(该exam
软件包没有我想要的这种功能,所以这就是我在这里询问的原因。)
编辑:因为 egreg 给了我以紧凑方式对齐四个选项的答案。我仍然看到在问题标题后放置虚线并可选择在那里放置正确答案或空白括号的一些改进。因此,对于 egreg 的源代码,如果我这样写:
\begin{choices}
This is the question.\par
\choice0 apple
\choice1 banana
\choice0 orange
\choice0 pear
\end{choices}
Or, it is better to put the question before the choices environment.
This is the question.
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orange
\choice0 pear
\end{choices}
I would suggest that the output should be:
This is the question...................................( )
A. apple B. banana
C. orange, eeeeeeeee D. pear
Or if need to show the correct answer
This is the question...................................(B)
A. apple B. banana
C. orange, eeeeeeeee D. pear
谢谢。
编辑2: 正如 minthao_2011 在评论中所说,下面的代码存在一些问题,长选择不会换行,请参见下面的图片。
\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}
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orange
\choice0 pear
\end{choices}
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orang, eeeeeeeee
\choice0 pear
\end{choices}
\showcorrecttrue
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orange, eeeeeeeee, eeeeeeeee, eeeeeeeee
\choice0 pear
\end{choices}
\begin{choices}
\choice0 This is a very long question. This is a very long question. This is a very long question. This is a very long question.
\choice1 This is a very long question. This is a very long question. This is a very long question. This is a very long question.
\choice0 This is a very long question. This is a very long question. This is a very long question. This is a very long question.
\choice0 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{choices}
\end{document}
答案1
带有environ
一些低级的 TeX。
\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}
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orange
\choice0 pear
\end{choices}
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orang, eeeeeeeee
\choice0 pear
\end{choices}
\showcorrecttrue
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orange, eeeeeeeee, eeeeeeeee, eeeeeeeee
\choice0 pear
\end{choices}
\end{document}
我首先用一个盒子将物品装箱,\halign
以便测量它们。这样我就可以根据指定的情况设置长度,然后重新排版物品。我还添加了一个标记正确答案的条件。
答案2
在越南,作者 Nguyen Huu Dien 有一个包。你可以在这里下载http://www.mediafire.com/download/5mxmnzty4jm/dethitracnghiem.zip. 网站首页是http://nhdien.wordpress.com/
\documentclass[11pt]{vieexamdesign}
\usepackage{amsmath,amsxtra,latexsym, amssymb, amscd}
\usepackage[utf8]{vietnam}
\usepackage{pstricks-add}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{times}
\usepackage{ifthen}
\usepackage{dethi} %Gói lệnh cho đề thi Việt Nam
%\usepackage{enumitem}
\usepackage{enumerate}
\usepackage{verbatim}
%\usepackage{hyper}
\Fullpages %Định dạng trang đề thi
\ContinuousNumbering
\ShortKey
\NumberOfVersions{1}
\SectionPrefix{\relax }
\tentruong{University}
\tenkhoa{Mathematica}
\loaidethi{K51 (ĐỀ THI CHÍNH THỨC)}
\tenkythi{Test}
\tenmonhoc{Subject}
\thoigian{Time: 90''}
\madethi{110}
\tieudetracnghiem
%\tieudethiviet
\tieudedapan
%\tieudetren
\tieudeduoi
\chucauhoi{Problem}
\mauchu{black}
\socauhoi{60}
\sotrang{4}
\setlength{\baselineskip}{12truept}
\def\v#1{\overrightarrow{#1}}
\def\v#1{\overrightarrow{#1}}
\usepackage{listings}
\begin{document}
\setlength{\baselineskip}{10truept}
\begin{multiplechoice}[title={\it Choose the correct answer of each question} , rearrange=yes , keycolumns=6]%
\begin{question}%1
$2 + 2 = $
\datcot
\bonpa
{\sai{1}}
{\sai{3}}
{\dung{4}}
{\sai{2}}
\end{question}
\begin{question}%2
This is a question \datcot[2]
\bonpa
{\sai{Wrong answer.}}
{\dung{Right answer.}}
{\sai{Wrong answer.}}
{\sai{Wrong answer.}}
\end{question}
\begin{question}%2
This is a question \datcot
\bonpa
{\sai{Long question Long question Long question Long question answer.}}
{\dung{Long question Long question Long question Long question answer.}}
{\sai{Long question Long question Long question Long question answer. }}
{\sai{Long question Long question Long question Long question answer .}}
\end{question}
\end{multiplechoice}
\end{document}
另一个包也是越南的。你可以在这里下载http://mathblog.org/cai-dat-va-su-dung-phan-mem-lam-de-trac-nghiem/EX_测试。
\documentclass[12pt,a4paper]{article}
\usepackage{ex_test}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}\usepackage{enumerate}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm] {geometry}
\begin{document}
\noindent
\begin{minipage}[b]{6cm}
\centerline{\textbf{\fontsize{13}{0}\selectfont Manchester University}}
\centerline{\rule{1.7in}{1pt}}
\centerline{\fontsize{13}{0}\selectfont Let's try}
\centerline{(\textit{Test containts \sotrang\ page(s)})}
\end{minipage}\hspace{1.5cm}
\begin{minipage}[b]{11cm}
\centerline{\textbf{\fontsize{13}{0}\selectfont Year 2013 - 2014}}
\centerline{\textbf{\fontsize{12}{0}\selectfont Subject: Math}}
\centerline{\textit{\fontsize{12}{0}\selectfont Times for Test: 90 minustes}}
\centerline{}
\end{minipage}\\[0.1cm]
\rightline{
\setlength\fboxrule{2pt}
\setlength\fboxsep{5pt}
\fbox{\bf Code of Test \made}
}
\noindent
\begin{minipage}[b]{10cm}
\textbf{Name of student:}\dotfill\\
\textbf{Number:}\dotfill
\end{minipage}\\
\Opensolutionfile{ans}[ans1]
\begin{ex}
The real solutions of the equation $x^2 - 2x - 3 = 0$ are
\boncot{$-1$ and $3$}{$1$ and $3$}{$1$ and $-3$}{$1$ and $3$}
\begin{sol}
A
\end{sol}
\end{ex}
\begin{ex}
The real solutions of the equation $x^2 - 2x - 3 = 0$ are
\haicot{$-1$ and $3$}{$1$ and $3$}{$1$ and $-3$}{$1$ and $3$}
\begin{sol}
A
\end{sol}
\end{ex}
\begin{ex}
The real solutions of the equation $x^2 - 2x - 3 = 0$ are
\motcot{$-1$ and $3$}{$1$ and $3$}{$1$ and $-3$}{$1$ and $3$}
\begin{sol}
A
\end{sol}
\end{ex}
\begin{ex}
This is a long question This is a long question This is a long question
\motcot{This is a long question This is a long question This is a long question This is a long question This is a long question This is a long question}{This is a long question This is a long question This is a long question This is a long question This is a long question This is a long question}{This is a long question This is a long question This is a long question This is a long question This is a long question This is a long question}{This is a long question This is a long question This is a long question This is a long question This is a long question This is a long question}
\begin{sol}
A
\end{sol}
\end{ex}
\Closesolutionfile{ans}
\indapan
\begin{multicols}{10}
\input{ans1}
\end{multicols}
\end{document}
注意
- motcot:一列;
- haicot:两列;
- boncot:四列。修复Tex后,使用Ex_test.batch 运行程序。可以制作多个版本。
答案3
该解决方案与 egreg 的解决方案类似,但对长项目和语法进行了一些细微的改进。
\documentclass{article}
\usepackage{environ}
\usepackage[normalem]{ulem}
\makeatletter
\newlength\choiceitemwidth
\newif\ifshowsolution \showsolutiontrue
\newcounter{choiceitem}
\def\thechoiceitem{\Alph{choiceitem}}
\def\makechoicelabel#1{#1\uline{\thechoiceitem.}\else\thechoiceitem.\fi\space}
\def\choice@mesureitem#1{\cr\stepcounter{choiceitem}\makechoicelabel#1}
\def\choicemesureitem{\@ifstar
{\choice@mesureitem\ifshowsolution}%
{\choice@mesureitem\iffalse}}%
\def\choice@blockitem#1{%
\ifnum\value{choiceitem}>0\hfil\fi
\egroup\hskip0pt
\hbox to \choiceitemwidth\bgroup\refstepcounter{choiceitem}\makechoicelabel#1}
\def\choiceblockitem{\@ifstar
{\choice@blockitem\ifshowsolution}%
{\choice@blockitem\iffalse}}
\def\choice@paraitem#1{%
\par\refstepcounter{choiceitem}\makechoicelabel#1}
\def\choiceparaitem{\@ifstar
{\choice@paraitem\ifshowsolution}%
{\choice@paraitem\iffalse}}
\NewEnviron{choices}{%
\begingroup
\let\item\choicemesureitem
\setcounter{choiceitem}{0}%
\settowidth{\global\choiceitemwidth}{\vbox{\halign{##\hfil\cr\BODY\crcr}}}%
\endgroup
\trivlist\item\relax
\parindent0pt
\setcounter{choiceitem}{0}%
\ifdim\choiceitemwidth<0.25\columnwidth
\choiceitemwidth=0.25\columnwidth
\let\item\choiceblockitem
\bgroup\BODY\hfil\egroup
\else\ifdim\choiceitemwidth<0.5\columnwidth
\choiceitemwidth=0.5\columnwidth
\let\item\choiceblockitem
\bgroup\BODY\hfil\egroup
\else % \choiceitemwidth > 0.5\columnwidth
\let\item\choiceparaitem
\BODY
\fi\fi
\endtrivlist
}
\makeatother
\begin{document}
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text text
\begin{choices}
\item* foo
\item bar
\item* baz
\end{choices}
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text text
\begin{choices}
\item* foo
\item bar
\item* foo
\item bar
\end{choices}
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text text
\begin{choices}
\item* foo
\item bar
\item* foo
\item bar with long long text
\end{choices}
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text text
\begin{choices}
\item* foo
\item bar
\item* baz
\item text text text text text text text text text text
text text text text text text text text text text
\end{choices}
\showsolutionfalse
\begin{choices}
\item* foo
\item bar
\item* foo
\item bar
\end{choices}
\end{document}
答案4
@egreg @minthao_2011 我甚至没有考虑多行答案。
我有办法解决这个问题。使用小页面
\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}
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orange
\choice0 pear
\end{choices}
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orang, eeeeeeeee
\choice0 pear
\end{choices}
\showcorrecttrue
\begin{choices}
\choice0 apple
\choice1 banana
\choice0 orange, eeeeeeeee, eeeeeeeee, 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}